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

outdated

PushBots SDK, help you manage push notifications easily and effectivly.

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:pushbots_flutter/pushbots_flutter.dart';
import 'package:pushbots_flutter_example/RestartWidget.dart';

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

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

class _MyAppState extends State<MyApp> {
  String pbInitState = 'PushBots did not initialized yet...';
  String pbRegisterInfo = 'PushBots Register Status';

  bool switchState = true;

  RestartWidget restartWidget = new RestartWidget();

  Key key = UniqueKey();

  void restartApp() {
    setState(() {
      key = UniqueKey();
    });
  }


  @override
  void initState() {
    super.initState();
    initPushBots();

    PushbotsFlutter.setTags(["tag1", "tag2"]);
    PushbotsFlutter.removeTags(["tag1"]);
    //PushbotsFlutter.shareLocation(true);

    if (!PushbotsFlutter.listenForNotificationOpen().hasListener) {
      PushbotsFlutter
          .listenForNotificationOpen()
          .stream
          .listen((onData) {
        print("Main Dart opened: " + onData.toString());

      });
    }


    if (!PushbotsFlutter.listenForNotificationReceive().hasListener) {
      PushbotsFlutter
          .listenForNotificationReceive()
          .stream
          .listen((onData) {
        print("Main Dart recieved: " + onData.toString());

        Map value = json.decode(onData.toString());


        print("first" + value["message"] + value.toString());
      });
    }
  }

  Future<void> initPushBots() async {
    String initStatue;
    try {
      initStatue = await PushbotsFlutter.initialize("5e145ec41f0f854fca1e2b54", "", "", "");
    } on Exception {
      initStatue = 'Failed to get initialize push-bots.';
    }
    setState(() {
      pbInitState = initStatue;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      key: key,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin PushBots app'),
        ),
        body: Center(
          child: new Column(
            children: <Widget>[
              Text('$pbInitState\n'),
              Switch(
                value: switchState,
                onChanged: (val) => setState(() {
                  switchState = val;
                  PushbotsFlutter.toggleNotifications(switchState);



                 // restartWidget.restartApp(context);
                }),
              ),
              Text('$pbRegisterInfo\n'),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
0
pub points
0%
popularity

Publisher

verified publisherpushbots.com

PushBots SDK, help you manage push notifications easily and effectivly.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on pushbots_flutter