flutter_nearby_messages_api 0.0.7 flutter_nearby_messages_api: ^0.0.7 copied to clipboard
Google Nearby Message API for Flutter (Cross platforms).
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');
// Only android.
// Importance : Call this method after setting apikey ((setAPIKey))
await nearbyMessagesApi.setDistanceType(GNSDistanceType.typeEarshot);
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 FlatButton(
onPressed: () async {
await nearbyMessagesApi.publish('Nice to meet you #NTMY');
},
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'))
]),
),
),
);
}
}