ir_sensor_plugin 0.1.4

  • Readme
  • Changelog
  • Example
  • Installing
  • new68

ir_sensor_plugin #

This plugin allows Flutter applications to make use of the Infrared Sensor.

Usage #

Support only for Android. If the plugin is invoked on iOS, it will crash your app. Added permission in the Manifests:

    <uses-permission android:name="android.permission.TRANSMIT_IR" />

How to use the methods #

Check whether the device has an infrared emitter. Returns "true" if the device has an infrared emitter, else "false" .

final bool hasIrEmitter = await IrSensorPlugin.hasIrEmitter;

Query the infrared transmitter's supported carrier frequencies in Hertz.

final String getCarrierFrequencies = await IrSensorPlugin.getCarrierFrequencies;

Change the frequency with which it is transmitted. Default is 38020 Hz

final String result = await IrSensorPlugin.setFrequencies(40000);

Transmit an infrared pattern, return a String "Emitting" if there was no problem in the process.

The value pattern has to be a string that contains the behavior in HEX, example:

static const TV_POWER_HEX = "0000 006d 0022 0003 00a9 00a8 0015 003f 0015 
003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 
0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 
0015 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 
0015 0040 0015 0015 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 
003f 0015 0702 00a9 00a8 0015 0015 0015 0e6e";

final String result = await IrSensorPlugin.transmitString(pattern: TV_POWER_HEX);

The value list has to be a list of Int, for example:

var power = [169,168,21,63,21,63,21,63,21,63,21,63,21,63,21,63,21,1794,169,168,21,21,21,3694];

final String result = await IrSensorPlugin.transmitListInt(list: power);

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.0.1 #

  • TODO: Describe initial release.

0.0.2 #

  • Update README.md

0.0.3 #

  • Apply suggestions

0.1.4 #

  • Rename the transmit() method to transmitString().
  • The setFrequencies() method is added.
  • The transmitListInt() method is added.
  • Updated example.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:ir_sensor_plugin/ir_sensor_plugin.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  bool _hasIrEmitter = false;
  String _getCarrierFrequencies = 'Unknown';

  var power = [
    169,
    168,
    21,
    63,
    21,
    63,
    21,
    63,
    21,
    63,
    21,
    63,
    21,
    63,
    21,
    63,
    21,
    1794,
    169,
    168,
    21,
    21,
    21,
    3694
  ];

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    bool hasIrEmitter;
    String getCarrierFrequencies;

    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await IrSensorPlugin.platformVersion;
      hasIrEmitter = await IrSensorPlugin.hasIrEmitter;
      getCarrierFrequencies = await IrSensorPlugin.getCarrierFrequencies;
    } on PlatformException {
      platformVersion = 'Failed to get data in a platform.';
      hasIrEmitter = false;
      getCarrierFrequencies = 'None';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
      _hasIrEmitter = hasIrEmitter;
      _getCarrierFrequencies = getCarrierFrequencies;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Container(
                height: 15.0,
              ),
              Text('Running on: $_platformVersion\n'),
              Text('Has Ir Emitter: $_hasIrEmitter\n'),
              Text('IR Carrier Frequencies:$_getCarrierFrequencies'),
              Container(
                height: 15.0,
              ),
              RaisedButton(
                onPressed: () async {
                  final String result =
                      await IrSensorPlugin.transmitListInt(list: power);
                  debugPrint('Emitting  List Int Signal: $result');
                },
                child: Text('Transmitt List Int'),
              ),
              Container(
                height: 15.0,
              ),
              FormSpecificCode(),
            ],
          ),
        ),
      ),
    );
  }
}

class FormSpecificCode extends StatelessWidget {
  final _formKey = GlobalKey<FormState>();
  final _textController = TextEditingController();
  static const power =
      "0000 006d 0022 0003 00a9 00a8 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 003f 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 003f 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0015 0040 0015 0015 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 003f 0015 0702 00a9 00a8 0015 0015 0015 0e6e";

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      Form(
          key: _formKey,
          child: Column(children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: TextFormField(
                decoration: InputDecoration(
                  hintText: 'Write specific String code to transmit',
                  suffixIcon: IconButton(
                    onPressed: () => _textController.clear(),
                    icon: Icon(Icons.clear),
                  ),
                ),
                controller: _textController,
                validator: (value) {
                  if (value.isEmpty) {
                    return 'Write the code to transmit';
                  }
                  return null;
                },
              ),
            )
          ])),
      Container(
        height: 15.0,
      ),
      RaisedButton(
        onPressed: () async {
          if (_formKey.currentState.validate()) {
            final String result = await IrSensorPlugin.transmitString(
                pattern: _textController.text);
            if (result.contains('Emitting') && result != null) {
              Scaffold.of(context).showSnackBar(SnackBar(
                  content: Text('Broadcasting... ${_textController.text}')));
            }
          }
        },
        child: Text('Transmit Specific Code HEX'),
      )
    ]);
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ir_sensor_plugin: ^0.1.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ir_sensor_plugin/ir_sensor_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:ir_sensor_plugin/ir_sensor_plugin.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:ir_sensor_plugin/ir_sensor_plugin.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:ir_sensor_plugin/ir_sensor_plugin.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:ir_sensor_plugin/ir_sensor_plugin.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • ir_sensor_plugin that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test