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

outdated

Google Nearby Message API for Flutter (Cross platforms).

FLUTTER NEARBY MESSAGES API #

Google Nearby Messages API for Flutter

Installation #

First, add flutter_nearby_messages_api as a dependency in your pubspec.yaml file.

iOS #

Get and add a google cloud nearby messages API key to your project https://developers.google.com/nearby/messages/ios/get-started

nearbyMessagesApi.setAPIKey('API_KEY');

Add two rows to the ios/Runner/Info.plist:

  • Privacy - Microphone Usage Description and a usage description. (For example description, "The microphone listens for anonymous tokens from nearby devices.")
  • Privacy - Bluetooth Peripheral Usage Description and a usage description. (For example description, "An anonymous token is advertised via Bluetooth to discover nearby devices.")

Or in text format add the key:

<key>NSMicrophoneUsageDescription</key>
<string>The microphone listens for anonymous tokens from nearby devices</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>An anonymous token is advertised via Bluetooth to discover nearby devices</string>

Android #

Get and add a google cloud nearby messages API key to your project https://developers.google.com/nearby/messages/android/get-started

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.sample.app" >
    <application ...>
        <meta-data
            android:name="com.google.android.nearby.messages.API_KEY"
            android:value="API_KEY" />
        <activity>
        ...
        </activity>
    </application>
</manifest>

Example #

import 'package:flutter_nearby_messages_api/flutter_nearby_messages_api.dart';

class main {
    /**
    * This method gets the message when an a nearby device sends one
    */
    static void onFound(dynamic arguments) {
      print(arguments);
    }
    
    /**
    * This method gets the message when a nearby device leaves
    */
    static void onLost(dynamic arguments) {
      print(arguments);
    }

    // init NearbyMessagesApi
    FlutterNearbyMessagesApi nearbyMessagesApi = FlutterNearbyMessagesApi(onFound, onLost);
 
    Future<void> main() async {
      // config for iOS
      await nearbyMessagesApi.setAPIKey('API_KEY');
      /**
      * Publishing a message
      * @require message
      */
      await nearbyMessagesApi.publish('message');
      /**
      * Subscribing
      */
      await nearbyMessagesApi.backgroundSubscribe();

      // Enable debug mode
      await nearbyMessageAPi.enableDebugMode()
      // Disable debug mode
      await nearbyMessageAPI.disableDebugMode()
    
    Future<void> dispose() async {
      // unPublish
      await nearbyMessagesApi.unPublish();
      // backgroundUnsubscribe
      await nearbyMessagesApi.backgroundUnsubscribe();
    }
}
22
likes
0
pub points
53%
popularity

Publisher

verified publishertmh-techlab.vn

Google Nearby Message API for Flutter (Cross platforms).

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_nearby_messages_api