infinea_sdk_flutter 0.0.1+1
infinea_sdk_flutter: ^0.0.1+1 copied to clipboard

Flutter Plugin for Infinite Peripherals Infinea SDK. This plugin allows you to connect and use devices compatible with Infinea SDK.

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  String sdkVersion = '';
  List _devicesInfo = [];
  bool passThroughSyncReturnValue = false;
  String _errorMessage;
  List events = [];
  InfineaSdkFlutter infinea;
  Function cancelListener;

  @override
  void dispose() {
    cancelListener();
    super.dispose();
  }

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> init() async {
    infinea = InfineaSdkFlutter();
    try {
      await infinea.setDeveloperKey(key: 'enteryourdeveloperkeyhere');
      print('set developer key');
    } catch (e) {
      print(e);
    }

    /*  try {
      await InfineaSdkFlutter.connect();
    } catch (e) {
      print(e);
    }*/
    // 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(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          children: [
            TextButton(
              onPressed: () async {
                sdkVersion = await InfineaSdkFlutter.sdkVersion;
                setState(() {});
              },
              child: Text('SDK VERSION'),
            ),
            Text(sdkVersion),
            TextButton(
              onPressed: () async {
                cancelListener = infinea.startListening((event) {
                  if (event['event'] == 'barcode') {
                    setState(() {
                      events.add(event);
                    });
                  }
                });
                await infinea.connect();
              },
              child: Text('Connect'),
            ),
            TextButton(
              onPressed: () async {
                await infinea.disconnect();
              },
              child: Text('Disconnect'),
            ),
            TextButton(
              onPressed: () async {
                try {
                  _devicesInfo = await infinea.getConnectedDevicesInfo();
                  _errorMessage = null;
                } catch (e) {
                  _errorMessage = e.toString();
                  _devicesInfo = null;
                }
                setState(() {});
              },
              child: Text('Get Connected Devices Info'),
            ),
            TextButton(
              onPressed: () async {
                try {
                  if (passThroughSyncReturnValue == true) {
                    passThroughSyncReturnValue =
                        await infinea.setPassThroughSync(value: false);
                  } else {
                    passThroughSyncReturnValue =
                        await infinea.setPassThroughSync(value: true);
                  }
                  setState(() {
                    _errorMessage = null;
                  });
                } catch (e) {
                  setState(() {
                    _errorMessage = e.toString();
                  });
                }
              },
              child: Text('Set Passthrough Sync'),
            ),
            _devicesInfo != null ? Text(_devicesInfo.toString()) : Container(),
            _errorMessage != null ? Text(_errorMessage) : Container(),
            Text("Events:"),
            Text(events.toString()),
            Text(passThroughSyncReturnValue.toString()),
          ],
        ),
      ),
    );
  }
}
0
likes
110
pub points
29%
popularity

Flutter Plugin for Infinite Peripherals Infinea SDK. This plugin allows you to connect and use devices compatible with Infinea SDK.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on infinea_sdk_flutter