infinea_sdk_flutter 0.0.2+1 copy "infinea_sdk_flutter: ^0.0.2+1" to clipboard
infinea_sdk_flutter: ^0.0.2+1 copied to clipboard

PlatformiOS

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: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: 'yourdeveloperkeyhere');
      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()),
          ],
        ),
      ),
    );
  }
}
1
likes
120
pub points
58%
popularity

Publisher

unverified uploader

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