pushwoosh 1.19.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

Installation #

  1. Install the library from pub:
dependencies:
  pushwoosh: '^1.19.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();

Guide #

https://www.pushwoosh.com/docs/flutter-plugin-integration

1.9.0 #

Updated #

  • Android SDK version updated to 5.9.0
  • iOS SDK version updated to 5.9.0

Added #

  • Message inbox support

1.9.1 #

Added #

  • pushwoosh_inbox README

Fixed #

  • removed duplicates from changelog

1.11.0 #

Updated #

  • Android SDK version updated to 5.11.0
  • iOS SDK version updated to 5.11.0
  • startLocationTracking is async now
  • compatibility with flutter v0.10.0+

1.12.0 #

Fixed #

  • Flutter plugin updated to build with Swift libraries

Updated #

  • Android SDK version updated to 5.12.1
  • iOS SDK version updated to 5.12.1

1.12.1 #

Fixed #

  • Crash on iOS 9

1.13.0 #

Fixed #

  • Fixed an issue with Flutter app crashes on push receiving while the app is terminated
  • Sample upgraded to Android X, gradle plugin version updated to 3.2.1

1.14.0 #

Fixed #

  • Zip Path Traversal Vulnerability

Updated #

  • Android SDK version updated to 5.14.3
  • iOS SDK version updated to 5.13.1

1.14.1 #

Fixed #

  • An issue with Android app crashes on launch

Updated #

  • Android SDK version updated to 5.14.4

1.17.0 #

Fixed #

  • An issue with opPushAccepted and onPushReceived callbacks not working when Flutter apps are opened by tap on a push notification

1.17.1 #

Fixed #

  • Flutter Android cannot receive push when app is on foreground

1.18.0 #

Added #

  • setMultiNotificationMode function for android

1.19.0 #

iOS #

  • Replaced UIWebView with WKWebView in iOS

Android #

  • Fixed ANRs caused by push messages being processed in the main thread in Android
  • Fixed incorrect inbox URL opening behaviour
  • Fixed background processing that caused extra battery consumption

Updated #

  • Android SDK version updated to 5.19.5
  • iOS SDK version updated to 5.19.3

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';
import 'package:pushwoosh_inbox/pushwoosh_inbox.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.setShowForegroundAlert(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": "5927F-D517A", "sender_id": "YOUR_SENDER_ID"});

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

    Pushwoosh pushwoosh = Pushwoosh.getInstance;

    pushwoosh.onPushReceived.listen((PushEvent event) {
      var message = event.pushwooshMessage;
      print("onPushReceived" + message.payload.toString());

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

    pushwoosh.onPushAccepted.listen((event) {
      var message = event.pushwooshMessage;
      print("onPushAccepted" + message.payload.toString());

      setState(() {
        _message = "Push Accepted:\n" + message.payload.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() async {
    try {
      await PushwooshGeozones.startLocationTracking();
    } catch(e){
      _message = e.toString();
      addLog();
    }


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

  void _stopLocationTracking() {
    PushwooshGeozones.stopLocationTracking();

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

  void _showInbox() {
    PWInboxStyle style = PWInboxStyle();

    style.dateFormat = "dd.MM.yyyy";

    style.defaultImage = "assets/inbox-1.png";
    style.unreadImage = "assets/bubble-2.png";
    style.listErrorImage = "assets/alert-2.png";
    style.listEmptyImage = "assets/inbox-1.png";
    
    style.listErrorMessage = "Custom error message";
    style.listEmptyMessage = "Custom empty message";
    style.barTitle = "Custom inbox title";

    style.accentColor = "#FF00FF";
    style.backgroundColor = "#FFFF00";
    style.highlightColor = "#FF0FFF";

    style.imageTypeColor = "#00F0FF";
    style.readImageTypeColor = "#FF000F";

    style.titleColor = "#00F0FF";
    style.readTitleColor = "#00FF0F";
    style.defaultTextColor = "#FF00FF";

    style.descriptionColor = "#FF000F";
    style.readDescriptionColor = "#00FF0F";

    style.dateColor = "#00F0FF";
    style.readDateColor = "#F0FF0F";

    style.dividerColor = "#FF000F";

    style.barBackgroundColor = "#FF000F";
    style.barAccentColor = "#0000FF";
    style.barTextColor = "#00FF00";
    
    PushwooshInbox.presentInboxUI(style: style);
  }

  @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('showInbox'),
                          onPressed: () => _showInbox(),
                        ),
                        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.19.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
70
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Dec 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/pushwoosh.dart.

Run flutter format to format lib/pushwoosh.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8