wearable_communicator 0.1.1 copy "wearable_communicator: ^0.1.1" to clipboard
wearable_communicator: ^0.1.1 copied to clipboard

Communication layer between a Flutter project for Android and IOS.

example/lib/main.dart

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

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

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

class _MyAppState extends State<MyApp> {
  TextEditingController _controller;
  String value = '';

  @override
  void initState() {
    super.initState();
    _controller = TextEditingController();

    WearableListener.listenForMessage((msg) {
      print(msg);
    });
    WearableListener.listenForDataLayer((msg) {
      print(msg);
    });
  }

  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              TextField(
                controller: _controller,
                decoration: InputDecoration(border: InputBorder.none, labelText: 'Enter some text'),
                onChanged: (String val) async {
                  setState(() {
                    value = val;
                  });
                },
              ),
              ElevatedButton(
                child: Text('Send message to wearable'),
                onPressed: () {
                  primaryFocus.unfocus(disposition: UnfocusDisposition.scope);
                  WearableCommunicator.sendMessage({"text": value});
                },
              ),
              ElevatedButton(
                child: Text('set data on wearable'),
                onPressed: () {
                  primaryFocus.unfocus(disposition: UnfocusDisposition.scope);
                  WearableCommunicator.setData("message", {
                    "text": value != "" ? value : "test", // ensure we have at least empty string
                    "integerValue": 1,
                    "intList": [1, 2, 3],
                    "stringList": ["one", "two", "three"],
                    "floatList": [1.0, 2.4, 3.6],
                    "longList": []
                  });
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
23
likes
40
pub points
37%
popularity

Publisher

unverified uploader

Communication layer between a Flutter project for Android and IOS.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on wearable_communicator