flutter_google_message_api 0.0.2 copy "flutter_google_message_api: ^0.0.2" to clipboard
flutter_google_message_api: ^0.0.2 copied to clipboard

A plugin that allows you to use google messageApi easily for a two-way communication between a device with android wear and the phone.

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

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

  FlutterGoogleMessageApi _msgApi = FlutterGoogleMessageApi();
  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    _msgApi.init();
    _msgApi.onConnected = () {
      print("Connected");
    };
    _msgApi.onInit = () {
      print("Initialized");
    };
    _msgApi.onMessage = (String msg) {
      print("New message: $msg");
    };
    _msgApi.onSuspended = () {
      print("Suspended");
    };

    // Platform messages may fail, so we use a try/catch PlatformException.

    // 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;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('MessageApi test'),
        ),
        body: Center(
          child: FlatButton(
            child: Text("Send message"),
            onPressed: () => {_msgApi.sendMessage("Test message")},
          ),
        ),
      ),
    );
  }
}
0
likes
30
pub points
0%
popularity

Publisher

unverified uploader

A plugin that allows you to use google messageApi easily for a two-way communication between a device with android wear and the phone.

License

GPL-3.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_google_message_api