flutter_plugin_engagelab 1.0.0 copy "flutter_plugin_engagelab: ^1.0.0" to clipboard
flutter_plugin_engagelab: ^1.0.0 copied to clipboard

A new Flutter plugin.

example/lib/main.dart

import 'dart:io';

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

import 'package:flutter/services.dart';
import 'package:flutter_plugin_engagelab/flutter_plugin_engagelab.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _event_name = 'Unknown';
  String _event_data = 'Unknown';

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    FlutterPluginEngagelab.addEventHandler(
        onMTCommonReceiver: (Map<String, dynamic> message) async {
      FlutterPluginEngagelab.printMy("flutter onMTCommonReceiver: $message");
      String event_name = message["event_name"];
      String event_data = message["event_data"];
      FlutterPluginEngagelab.printMy("flutter onMTCommonReceiver event_name: " + event_name);
      FlutterPluginEngagelab.printMy("flutter onMTCommonReceiver event_data: " + event_data);
      setState(() {
        _event_name = "$event_name";
        _event_data = "$event_data";
        // debugLable = "flutter onMTCommonReceiver: $message";
        if (Comparable.compare(event_name, "onConnectStatus") == 0 ||
            Comparable.compare(event_name, "networkDidLogin") == 0) {
          if (Comparable.compare(event_data, "true") == 0) {
            FlutterPluginEngagelab.getRegistrationId().then((rid) {
              FlutterPluginEngagelab.printMy("flutter get registration id : $rid");
              setState(() {
                _platformVersion = "$rid";
              });
            });
          }
        }
      });
    });
    FlutterPluginEngagelab.configDebugMode(true);
    if (Platform.isIOS) {
      FlutterPluginEngagelab.initIos(
        appKey: "fcc545917674d6f06c141704",
        channel: "testChannel",
      );
    } else if (Platform.isAndroid) {
      FlutterPluginEngagelab.initAndroid();
    }

    String platformVersion = "";
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    FlutterPluginEngagelab.getRegistrationId().then((rid) {
      FlutterPluginEngagelab.printMy("flutter get registration id : $rid");
      setState(() {
        _platformVersion = "$rid";
      });
    });
    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('RID: $_platformVersion\n'
              'EVENT NAME: $_event_name\n'
              'EVENT DATA: $_event_data\n'),
        ),
      ),
    );
  }
}
1
likes
0
pub points
86%
popularity

Publisher

unverified uploader

A new Flutter plugin.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_plugin_engagelab