pushwoosh 1.8.0

  • README.md
  • Example
  • Installing
  • Versions
  • 26

Installation

  1. Install the library from pub:
dependencies:
  pushwoosh: '^1.8.0'
  1. Configure Firebase Android project in Firebase console.

  2. Place a google-services.json file into android/app folder in your project directory.

Usage

import 'package:pushwoosh/pushwoosh.dart';
...
Pushwoosh.initialize({"app_id": "YOUR_APP_ID", "sender_id": "FCM_SENDER_ID"});
Pushwoosh.getInstance.onPushReceived.listen((event) {
...
});
Pushwoosh.getInstance.onPushAccepted.listen((event) {
...
});
Pushwoosh.getInstance.registerForPushNotifications();

example/lib/main.dart

import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pushwoosh/pushwoosh.dart';
import 'package:pushwoosh_geozones/pushwoosh_geozones.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _message = "Waiting..";
  String _log = "";
  bool _showAlert = false;

  set showAlert(bool value) {
    _showAlert = value;
    Pushwoosh.getInstance.showForegroundAlert = value;
  }

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    Pushwoosh.initialize({"app_id": "YOUR_APP_ID", "sender_id": "YOUR_SENDER_ID"});

    setState(() {
      _message = "Ready";
      addLog();
    });

    Pushwoosh pushwoosh = Pushwoosh.getInstance;

    pushwoosh.onPushReceived.listen((PushEvent event) {
      var message = event.pushwooshMessage;

      setState(() {
        _message = "Push Received:\n" + message.payload.toString();
        addLog();
      });
    });

    pushwoosh.onPushAccepted.listen((event) {
      var message = event.pushwooshMessage;
      setState(() {
        _message = 
        "message: " + message.message
        + "\ntitle: " + message.title
        + "\ncustom data: " + message.customData.toString()
        + "\nfrombackground: " + event.fromBackground.toString();
        addLog();
      });
    });

    _showAlert = await pushwoosh.showForegroundAlert;
  }

  void _registerForPushNotifications() async {
    Pushwoosh pushwoosh = Pushwoosh.getInstance;

    String token = "empty";
    try {
      token = await pushwoosh.registerForPushNotifications();
    } catch (e) {
      token = e.toString();
    }

    setState(() {
      _message = "Registered for pushes with token: " + token;
      addLog();
    });
  }

  void _unregisterForPushNotifications() async {
    Pushwoosh pushwoosh = Pushwoosh.getInstance;

    String result = "Unregistered from push notifications";

    try {
      await pushwoosh.unregisterForPushNotifications();
    } catch (e) {
      result = e.toString();
    }

    setState(() {
      _message = result;
      addLog();
    });
  }

  void _getTags() async {
    Pushwoosh pushwoosh = Pushwoosh.getInstance;

    Map<dynamic, dynamic> tags;
    try {
      tags = await pushwoosh.getTags();
    } catch (e) {
      setState(() {
        _message = "Get tags failed:\n" + e.toString();
        addLog();
      });
    }

    setState(() {
      _message = "Tags:\n" + tags.toString();
      addLog();
    });
  }

  void _setTags() async {
    Pushwoosh pushwoosh = Pushwoosh.getInstance;

    Map<String, dynamic> tags = {"tag1": "value"};

    String result = "setTags completed: " + tags.toString();

    try {
      await pushwoosh.setTags(tags);
    } catch (e) {
      result = "Set tags failed:\n" + e.toString();
    }

    setState(() {
      _message = result;
      addLog();
    });
  }

  void _getHwid() async {
    String hwid = await Pushwoosh.getInstance.getHWID;

    setState(() {
      _message = "HWID: " + hwid;
      addLog();
    });
  }

  void _getToken() async {
    String token = await Pushwoosh.getInstance.getPushToken;

    setState(() {
      if (token != null) {
        _message = "Token: " + token;
      } else {
        _message = "No token";
      }
      addLog();
    });
  }

  void _postEvent() async {
    String result = "Event did sent";

    try {
      await Pushwoosh.getInstance.postEvent("appOpen", {"test": "test"});
    } catch (e) {
      result = e.toString();
    }

    setState(() {
      _message = result;
      addLog();
    });
  }

  void _startLocationTracking() {
    PushwooshGeozones.startLocationTracking();

    setState(() {
      _message = "Location tracking did start";
      addLog();
    });
  }

  void _stopLocationTracking() {
    PushwooshGeozones.stopLocationTracking();

    setState(() {
      _message = "Location tracking did stop";
      addLog();
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              tabs: [
                Tab(icon: Icon(Icons.phone_android)),
                Tab(icon: Icon(Icons.sms)),
              ],
            ),
            title: Text('Pushwoosh'),
          ),
          body: TabBarView(
            children: [
              new Column(
                children: <Widget>[
                  new Container(
                    child: Text('$_message'),
                    padding: EdgeInsets.all(20.0),
                    height: 100.0,
                  ),
                  new Expanded(
                    child: new ListView(
                      shrinkWrap: true,
                      padding: const EdgeInsets.all(20.0),
                      children: <Widget>[
                        new CupertinoButton(
                          child: Text('registerForPushNotifications'),
                          onPressed: () => _registerForPushNotifications(),
                        ),
                        new CupertinoButton(
                          child: Text('unregisterForPushNotifications'),
                          onPressed: () => _unregisterForPushNotifications(),
                        ),
                        new CupertinoButton(
                          child: Text('getTags'),
                          onPressed: () => _getTags(),
                        ),
                        new CupertinoButton(
                          child: Text('setTags'),
                          onPressed: () => _setTags(),
                        ),
                        new CupertinoButton(
                          child: Text('getHWID'),
                          onPressed: () => _getHwid(),
                        ),
                        new CupertinoButton(
                          child: Text('getPushToken'),
                          onPressed: () => _getToken(),
                        ),
                        new CupertinoButton(
                          child: Text('postEvent'),
                          onPressed: () => _postEvent(),
                        ),
                        new CupertinoButton(
                          child: Text('startLocationTracking'),
                          onPressed: _startLocationTracking,
                        ),
                        new CupertinoButton(
                          child: Text('stopLocationTracking'),
                          onPressed: _stopLocationTracking,
                        ),
                        new MergeSemantics(
                          child: new ListTile(
                            title: new Text('showForegroundAlert'),
                            trailing: new CupertinoSwitch(
                              value: _showAlert,
                              onChanged: (bool value) {
                                setState(() {
                                  this.showAlert = value;
                                  _message = "showForegroundAlert: " +
                                      value.toString();
                                });
                              },
                            ),
                            onTap: null,
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
              new ListView(
                  children: <Widget>[
                    new CupertinoButton(onPressed: _clearLog,
                      child: Text('Clear log')
                    ),
                    new Container(
                  child: Text('$_log'),
                  padding: EdgeInsets.all(5.0),
                )
                  ]
              )
            ],
          ),
        ),
      ),
    );
  }

  void _clearLog(){
    setState(() {
      _log = "";
    });
  }

  void addLog() {
    setState(() {
      _log += "\n\n" + _message;
    });
  }

}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  pushwoosh: ^1.8.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:pushwoosh/pushwoosh.dart';
  
Version Uploaded Documentation Archive
1.8.0 Jul 12, 2018 Go to the documentation of pushwoosh 1.8.0 Download pushwoosh 1.8.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
26
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <2.0.0