cleverpush_flutter 1.1.0

CleverPush Flutter SDK #

Documentation #

https://developers.cleverpush.com/sdks/flutter/

example/lib/main.dart

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

import 'package:cleverpush_flutter/cleverpush_flutter.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _debugLabelString = "";

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

  Future<void> initPlatformState() async {
    if (!mounted) return;

    CleverPush.shared.setNotificationReceivedHandler((CPNotificationReceivedResult result) {
      this.setState(() {
        _debugLabelString =
            "Notification received: \n${result.notification.jsonRepresentation().replaceAll("\\n", "\n")}";
      });
    });

    CleverPush.shared.setNotificationOpenedHandler((CPNotificationOpenedResult result) {
      this.setState(() {
        _debugLabelString =
            "Notification opened: \n${result.notification.jsonRepresentation().replaceAll("\\n", "\n")}";
      });
    });

    CleverPush.shared.setSubscribedHandler((subscriptionId) {
      print("Subscribed: ${subscriptionId}");
    });

    // CleverPush Channel ID
    await CleverPush.shared.init("7R8nkAxtrY5wy5TsS");
  }

  void _handleSubscribe() {
    print("Prompting for Permission");
    CleverPush.shared.subscribe();
  }

  void _handleUnsubscribe() {
    CleverPush.shared.unsubscribe();
  }

  void _handleIsSubscribed() {
    CleverPush.shared.isSubscribed().then((status) {
      this.setState(() {
        _debugLabelString = status.toString();
      });
    });
  }

  void _handleTopicsDialog() {
    CleverPush.shared.showTopicsDialog();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: const Text('CleverPush Flutter'),
            backgroundColor: Color.fromARGB(255, 33, 33, 33),
          ),
          body: Container(
            padding: EdgeInsets.all(10.0),
            child: SingleChildScrollView(
              child: new Table(
                children: [
                  new TableRow(children: [
                    new CleverPushButton(
                        "Subscribe", _handleSubscribe, true)
                  ]),
                  new TableRow(children: [
                    new CleverPushButton(
                        "Unsubscribe", _handleUnsubscribe, true)
                  ]),
                  new TableRow(children: [
                    new CleverPushButton(
                        "Is Subscribed?", _handleIsSubscribed, true)
                  ]),
                  new TableRow(children: [
                    new CleverPushButton("Show topics dialog", _handleTopicsDialog, true)
                  ]),
                  new TableRow(children: [
                    Container(
                      height: 8.0,
                    )
                  ]),
                  new TableRow(children: [
                    new Container(
                      child: new Text(_debugLabelString),
                      alignment: Alignment.center,
                    )
                  ]),
                ],
              ),
            ),
          )),
    );
  }
}

typedef void OnButtonPressed();

class CleverPushButton extends StatefulWidget {
  final String title;
  final OnButtonPressed onPressed;
  final bool enabled;

  CleverPushButton(this.title, this.onPressed, this.enabled);

  State<StatefulWidget> createState() => new CleverPushButtonState();
}

class CleverPushButtonState extends State<CleverPushButton> {
  @override
  Widget build(BuildContext context) {
    return new Table(
      children: [
        new TableRow(children: [
          new FlatButton(
            disabledColor: Color.fromARGB(100, 100, 100, 100),
            disabledTextColor: Colors.white,
            color: Color.fromARGB(255, 33, 33, 33),
            textColor: Colors.white,
            padding: EdgeInsets.all(8.0),
            child: new Text(widget.title),
            onPressed: widget.enabled ? widget.onPressed : null,
          )
        ]),
        new TableRow(children: [
          Container(
            height: 8.0,
          )
        ]),
      ],
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  cleverpush_flutter: ^1.1.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:cleverpush_flutter/cleverpush_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Health issues and suggestions

Document public APIs. (-1 points)

52 out of 52 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/notification.dart. (-0.50 points)

Analysis of lib/src/notification.dart reported 1 hint:

line 1 col 8: Unused import: 'package:flutter/foundation.dart'.

Format lib/cleverpush_flutter.dart.

Run flutter format to format lib/cleverpush_flutter.dart.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
test ^1.5.1