finbox_dc_plugin 1.0.14 copy "finbox_dc_plugin: ^1.0.14" to clipboard
finbox_dc_plugin: ^1.0.14 copied to clipboard

Device Connect Flutter SDK is used to collect anonymised non-PII data from the devices of the users after taking explicit user consent

example/lib/main.dart

import 'package:either_dart/either.dart';
import 'package:finbox_dc_plugin/finbox_dc_plugin.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'constants.dart';
import 'common.dart';

void main() {
  runApp(MyApp(key: null,));
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();
  late FirebaseMessaging _messaging;

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
        future: _initialization,
        builder: (context, snapshot) {
          // Check for errors
          if (snapshot.hasError) {
            // return SomethingWentWrong();
            print('Something went wrong in Flutter Fire');
          }

          if (snapshot.connectionState == ConnectionState.done) {
            print('firebase INIT');
            _messaging = FirebaseMessaging.instance;
            _messaging.getToken().then((value) => print("Fcm token: $value"));
            FirebaseMessaging.onMessage.listen((RemoteMessage event) {
              print("Message Received: ${event.data}");
              FinBoxDcPlugin.forwardFinBoxNotificationToSDK(event.data);
            });
            return MaterialApp(
              title: 'Flutter Demo',
              theme: ThemeData(
                primarySwatch: Colors.blue,
              ),
              home: HomePage(),
            );
          }

          return Container(
            color: Colors.white,
          );
        });
  }
}

class HomePage extends StatelessWidget {

  _createUser() {
    try {
      final hello = FinBoxDcPlugin.createUser(
          Constants.CLIENT_API_KEY, CommonUitl.getUsername());
      hello.fold(
          (left) => {
                // error response
                print("Error: $left")
              },
          (right) => {
                // success response
                print("Access Token: $right")
              });
    } on PlatformException catch (e) {
      print('Failed to fetch data: ${e.message}');
    }
  }

  _startPeriodicSync() {
    FinBoxDcPlugin.startPeriodicSync();
  }

  _stopPeriodicSync() {
    FinBoxDcPlugin.stopPeriodicSync();
  }

  _syncSmsData() {
    FinBoxDcPlugin.syncSmsData();
  }

  _syncLocationData() {
    FinBoxDcPlugin.syncLocationData();
  }

  _syncDeviceData() {
    FinBoxDcPlugin.syncDeviceData();
  }

  _syncAppsListData() {
    FinBoxDcPlugin.syncAppsListData();
  }

  _setSyncFrequency() {
    FinBoxDcPlugin.setSyncFrequency(36000);
  }

  _resetData() {
    FinBoxDcPlugin.resetData();
  }

  _forgetUser() {
    FinBoxDcPlugin.forgetUser();
  }

  _setDeviceMatch() {
    FinBoxDcPlugin.setDeviceMatch("email", "userName", "phone");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Device Connect Sample"),
      ),
      body: Center(
        child: Column(
          children: [
            ElevatedButton(
              onPressed: _createUser,
              child: Text("Create User"),
            ),
            ElevatedButton(
              onPressed: _setDeviceMatch,
              child: Text("Set Device Data"),
            ),
            ElevatedButton(
              onPressed: _setSyncFrequency,
              child: Text("Set Sync Frequency"),
            ),
            ElevatedButton(
              onPressed: _startPeriodicSync,
              child: Text("Start Periodic Sync"),
            ),
            ElevatedButton(
              onPressed: _stopPeriodicSync,
              child: Text("Stop Periodic Sync"),
            ),
            ElevatedButton(
              onPressed: _resetData,
              child: Text("Reset Data"),
            ),
            ElevatedButton(
              onPressed: _forgetUser,
              child: Text("Forget User"),
            ),
          ],
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
0
likes
0
pub points
90%
popularity

Publisher

verified publisherfinbox.in

Device Connect Flutter SDK is used to collect anonymised non-PII data from the devices of the users after taking explicit user consent

Repository (GitLab)
View/report issues

License

unknown (license)

Dependencies

either_dart, flutter

More

Packages that depend on finbox_dc_plugin