flutter_nearby_messages_api 0.0.1
flutter_nearby_messages_api: ^0.0.1 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> {
static void onFound(dynamic arguments) {
print("~~~~~~~onFound" + arguments.toString());
}
static void onLost(dynamic arguments) {
print("~~~~~~~onLost" + arguments.toString());
}
FlutterNearbyMessagesApi nearbyMessagesApi =
FlutterNearbyMessagesApi(onFound, onLost);
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// For iOS
nearbyMessagesApi.setAPIKey('API_KEY');
}
@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 FlatButton(
onPressed: () async {
await nearbyMessagesApi.publish('message');
},
child: new Text("publish")),
new FlatButton(
onPressed: () async {
await nearbyMessagesApi.unPublish();
},
child: new Text("unPublish")),
new FlatButton(
onPressed: () async {
await nearbyMessagesApi.backgroundSubscribe();
},
child: new Text("backgroundSubscribe")),
new FlatButton(
onPressed: () async {
await nearbyMessagesApi.backgroundUnsubscribe();
},
child: new Text("unSubscribe")),
new FlatButton(
onPressed: () async {
await nearbyMessagesApi.setGranted();
},
child: new Text("setGranted")),
]),
),
),
);
}
}