flutter_nearby_messages_api 0.0.8 copy "flutter_nearby_messages_api: ^0.0.8" to clipboard
flutter_nearby_messages_api: ^0.0.8 copied to clipboard

Google Nearby Message API for Flutter (Cross platforms).

example/lib/main.dart

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

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
  FlutterNearbyMessagesApi nearbyMessagesApi = FlutterNearbyMessagesApi();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // For iOS
    await nearbyMessagesApi.setAPIKey('API_KEY');

    nearbyMessagesApi.onFound = (message) {
      print('~~~onFound : $message');
    };

    nearbyMessagesApi.onLost = (message) {
      print('~~~onLost : $message');
    };

    nearbyMessagesApi.statusHandler = (status) {
      print('~~~statusHandler : $status');
    };

    nearbyMessagesApi.setPermissionAlert(
        'Your title', 'Your message', 'Deny', 'Grant');

    nearbyMessagesApi.permissionHandler = (status) {
      print(status);
    };

    nearbyMessagesApi.bluetoothPowerErrorHandler = (args) {
      print('~~~ bluetoothPowerErrorHandler');
    };

    nearbyMessagesApi.bluetoothPermissionErrorHandler = (args) {
      print('~~~ bluetoothPermissionErrorHandler');
    };

    nearbyMessagesApi.microphonePermissionErrorHandler = (args) {
      print('~~~ microphonePermissionErrorHandler');
    };

    // Do not use it if you have not learned it carefully
    // nearbyMessagesApi.setNearbyAccessPermission(true);
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Flutter Nearby Messages Example'),
        ),
        body: new Container(
          color: Colors.white70,
          child: new Column(children: [
            new TextButton(
                onPressed: () async {
                  await nearbyMessagesApi.publish('Hello world!');
                },
                child: new Text("publish")),
            new TextButton(
                onPressed: () async {
                  await nearbyMessagesApi.unPublish();
                },
                child: new Text("unPublish")),
            new TextButton(
                onPressed: () async {
                  await nearbyMessagesApi.backgroundSubscribe();
                },
                child: new Text("backgroundSubscribe")),
            new TextButton(
                onPressed: () async {
                  await nearbyMessagesApi.backgroundUnsubscribe();
                },
                child: new Text("unSubscribe"))
          ]),
        ),
      ),
    );
  }
}
22
likes
110
pub points
57%
popularity

Publisher

verified publishertmh-techlab.vn

Google Nearby Message API for Flutter (Cross platforms).

Homepage

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_nearby_messages_api