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

Enhanced Getui Flutter plugin with full payload support for push notifications. Fork of getuiflut with bug fixes and improvements.

example/lib/main.dart

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

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

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _payloadInfo = 'Null';
  String _userMsg = "";
  String _notificationState = "";
  String _getClientId = "";
  String _getDeviceToken = "";
  String _onReceivePayload = "";
  String _onReceiveNotificationResponse = "";
  String _onAppLinkPayLoad = "";

  // 已废�?
  // String _getVoipToken = "";
  // String _onReceiveVoipPayLoad;
  //final GetuiFlutter getui = new GetuiFlutter();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    String payloadInfo = "default";
    String notificationState = "default";
    // Platform messages may fail, so we use a try/catch PlatformException.

    if (Platform.isIOS) {
      getSdkVersion();
      GetuiFlutter().startSdk(
          appId: "xXmjbbab3b5F1m7wAYZoG2",
          appKey: "BZF4dANEYr8dwLhj6lRfx2",
          appSecret: "yXRS5zRxDt8WhMW8DD8W05");
    }

    try {
      platformVersion = await GetuiFlutter.platformVersion;

      print('platformVersion' + platformVersion);
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // 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;
      _payloadInfo = payloadInfo;
      _notificationState = notificationState;
    });

    GetuiFlutter().addEventHandler(onReceiveClientId: (String message) async {
      print("flutter onReceiveClientId: $message");
      setState(() {
        _getClientId = "ClientId: $message";
      });
    }, onReceiveMessageData: (Map<String, dynamic> msg) async {
      print("flutter onReceiveMessageData: $msg");
      setState(() {
        _payloadInfo = msg['payload'];
      });
    }, onNotificationMessageArrived: (Map<String, dynamic> msg) async {
      print("flutter onNotificationMessageArrived: $msg");
      setState(() {
        _notificationState = 'Arrived';
      });
    }, onNotificationMessageClicked: (Map<String, dynamic> msg) async {
      print("flutter onNotificationMessageClicked: $msg");
      setState(() {
        _notificationState = 'Clicked';
      });
    }, onTransmitUserMessageReceive: (Map<String, dynamic> msg) async {
      print("flutter onTransmitUserMessageReceive:$msg");
      setState(() {
        _userMsg = msg["msg"];
      });
    }, onRegisterDeviceToken: (String message) async {
      print("flutter onRegisterDeviceToken: $message");
      setState(() {
        _getDeviceToken = "$message";
      });
    }, onReceivePayload: (Map<String, dynamic> message) async {
      print("flutter onReceivePayload: $message");
      setState(() {
        _onReceivePayload = "$message";
      });
    }, onReceiveNotificationResponse: (Map<String, dynamic> message) async {
      print("flutter onReceiveNotificationResponse: $message");
      setState(() {
        _onReceiveNotificationResponse = "$message";
      });
    }, onAppLinkPayload: (String message) async {
      print("flutter onAppLinkPayload: $message");
      setState(() {
        _onAppLinkPayLoad = "$message";
      });
    }, onPushModeResult: (Map<String, dynamic> message) async {
      print("flutter onPushModeResult: $message");
    }, onSetTagResult: (Map<String, dynamic> message) async {
      print("flutter onSetTagResult: $message");
    }, onAliasResult: (Map<String, dynamic> message) async {
      print("flutter onAliasResult: $message");
    }, onQueryTagResult: (Map<String, dynamic> message) async {
      print("flutter onQueryTagResult: $message");
    }, onWillPresentNotification: (Map<String, dynamic> message) async {
      print("flutter onWillPresentNotification: $message");
    }, onOpenSettingsForNotification: (Map<String, dynamic> message) async {
      print("flutter onOpenSettingsForNotification: $message");
    }, onGrantAuthorization: (String granted) async {
      print("flutter onGrantAuthorization: $granted");
    }, onLiveActivityResult: (Map<String, dynamic> message) async {
      print("flutter onLiveActivityResult: $message");
    });
  }

  Future<void> initGetuiSdk() async {
    try {
      GetuiFlutter.initGetuiSdk;
    } catch (e) {
      e.toString();
    }
  }

  Future<void> getClientId() async {
    String getClientId;
    try {
      getClientId = await GetuiFlutter.getClientId;
      print(getClientId);
    } catch (e) {
      print(e.toString());
    }
  }

  Future<void> getSdkVersion() async {
    String ver;
    try {
      ver = await GetuiFlutter.sdkVersion;
      print(ver);
    } catch (e) {
      print(e.toString());
    }
  }

  Future<void> getLaunchNotification() async {
    Map info;
    try {
      info = await GetuiFlutter.getLaunchNotification;
      print(info);
    } catch (e) {
      print(e.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: ListView(
            children: <Widget>[
              Container(
                // height: 200,
                alignment: Alignment.center,

                child: Column(
                  children: <Widget>[
                    Text('platformVersion: $_platformVersion\n'),
                    Text('clientId: $_getClientId\n'),
                    Text(
                      'Android Public Function',
                      style: TextStyle(
                        color: Colors.lightBlue,
                        fontSize: 20.0,
                      ),
                    ),
                    Text('userMsg: $_userMsg\n'),
                    Text('payload: $_payloadInfo\n'),
                    Text('notificaiton state: $_notificationState\n'),
                    ElevatedButton(
                      onPressed: () {
                        initGetuiSdk();
                      },
                      child: const Text('initGetuiSdk'),
                    ),
                    Text(
                      'SDK Public Function',
                      style: TextStyle(
                        color: Colors.lightBlue,
                        fontSize: 20.0,
                      ),
                    ),
                    Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: <Widget>[
                          ElevatedButton(
                            onPressed: () {
                              if (Platform.isIOS) {
                                GetuiFlutter().onActivityCreate();
                              }
                            },
                            child: const Text('onActivityCreate'),
                          ),
                          ElevatedButton(
                            onPressed: () {
                              GetuiFlutter().setBadge(5);
                            },
                            child: const Text('setBadge'),
                          ),
                        ]),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                        ElevatedButton(
                          onPressed: () {
                            getClientId();
                          },
                          child: const Text('getClientId'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            GetuiFlutter().turnOffPush();
                          },
                          child: const Text('stop push'),
                        ),
                        // RaisedButton(
                        //   onPressed: () {
                        //     GetuiFlutter().turnOnPush();
                        //   },
                        //   child: const Text('resume push'),
                        // ),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                        ElevatedButton(
                          onPressed: () {
                            GetuiFlutter().bindAlias('test', 'test');
                          },
                          child: const Text('bindAlias'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            GetuiFlutter().unbindAlias('test', 'test', true);
                          },
                          child: const Text('unbindAlias'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            List test = List.filled(1, 'abc');
                            GetuiFlutter().setTag(test);
                          },
                          child: const Text('setTag'),
                        ),
                      ],
                    ),

                    Text(
                      'ios Public Function',
                      style: TextStyle(
                        color: Colors.redAccent,
                        fontSize: 20.0,
                      ),
                    ),
                    Text('DeviceToken: $_getDeviceToken'),
                    Text('onAppLinkPayload: $_onAppLinkPayLoad'),
                    Text('Payload: $_onReceivePayload'),
                    Text('APNs: $_onReceiveNotificationResponse'),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                        ElevatedButton(
                          onPressed: () {
                            getLaunchNotification();
                          },
                          child: const Text('getLaunchNotification'),
                        ),
                      ],
                    ),
                    Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: <Widget>[
                          ElevatedButton(
                            onPressed: () {
                              GetuiFlutter().setBadge(5);
                            },
                            child: const Text('setBadge'),
                          ),
                          ElevatedButton(
                            onPressed: () {
                              GetuiFlutter().setLocalBadge(0);
                            },
                            child: const Text('setLocalBadge(0)'),
                          ),
                        ]),
                    // 已废�?
                    // Text('VoipToken: $_getVoipToken'),
                    // Text('onReceiveVoipPayLoad: $_onReceiveVoipPayLoad'),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                        ElevatedButton(
                          onPressed: () {
                            GetuiFlutter().resetBadge();
                          },
                          child: const Text('resetBadge'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            GetuiFlutter().setPushMode(0);
                          },
                          child: const Text('setPushMode(0)'),
                        ),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                        ElevatedButton(
                          onPressed: () {
                            GetuiFlutter().startSdkSimple(
                                appId: "xXmjbbab3b5F1m7wAYZoG2",
                                appKey: "BZF4dANEYr8dwLhj6lRfx2",
                                appSecret: "yXRS5zRxDt8WhMW8DD8W05");
                          },
                          child: const Text('startSimple(仅启动sdk)'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            //需要先启动sdk
                            GetuiFlutter().registerRemoteNotification();
                          },
                          child: const Text('注册通知权限'),
                        ),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                        ElevatedButton(
                          onPressed: () {
                            //开发者需自行获取token
                            String token =
                                "8048e0825f0034231ce2f638743584f47fb4fd49b5a6ad2a8a91b154966997465e6292780ff648edfea69168cb5c0df55bdc1da919c7b423053f127dbc79b9520366c95bbc40d6c8c9b1f9f4d4c1e452";
                            GetuiFlutter().registerActivityToken(
                                'aid_01', token, 'sn_01');
                          },
                          child: const Text('registerActivityToken'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            GetuiFlutter().runBackgroundEnable(1);
                          },
                          child: const Text('runBackgroundEnable(0)'),
                        ),
                      ],
                    ),
                  ],
                ),
              )
            ],
          ),
        ));
  }
}
1
likes
130
points
145
downloads

Publisher

unverified uploader

Weekly Downloads

Enhanced Getui Flutter plugin with full payload support for push notifications. Fork of getuiflut with bug fixes and improvements.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on getui_flutter

Packages that implement getui_flutter