stream_notifications 1.0.0

stream_notifications #

A new Flutter plugin.

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Getting Started #

Setup #

Android: Register service in the manifest #

The plugin uses an Android system service to track notifications. To allow this service to run the following code should be put inside the Android manifest, between the <application></application> tags.

 <service android:name="jd.com.stream_notifications.NotificationListener"
          android:label="notifications"
          android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
          <intent-filter>
            <action android:name="android.service.notification.NotificationListenerService" />
          </intent-filter>
 </service>

Use #

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

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

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

class _MyAppState extends State<MyApp> {
  StreamNotifications _notifications;
  StreamSubscription<LiveNotificationEvent> _subscription;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    startListening();
  }

  void onData(LiveNotificationEvent event) {
    print(event.toString());
  }

  void startListening() {
    _notifications = new StreamNotifications();
    try {
      _subscription = _notifications.notificationStream.listen(onData);
    } on NotificationException catch (exception) {
      print(exception);
    }
  }

  void stopListening() {
    _subscription.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
      ),
    );
  }
}

0.0.1 #

  • TODO: Describe initial release.

example/README.md

stream_notifications_example #

Demonstrates how to use the stream_notifications plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Analysis issues and suggestions

Make sure flutter format successfully runs on your package's source files.

Running flutter format failed with the following output:

Exception: dartfmt on lib/ failed with exit code 65
Could not format because the source could not be parsed:

line 18, column 41 of lib/stream_notifications.dart: Expected to find ','.
   ╷
18 │             .map((event) => _notifica   tionEvent(event));
   │                                         ^^^^^^^^^
   ╵
Formatting failed: 65

Health issues and suggestions

Fix lib/stream_notifications.dart. (-76.39 points)

Analysis of lib/stream_notifications.dart failed with 5 errors, 1 hint, including:

line 18 col 17: Too many positional arguments: 1 expected, but 2 found.

line 18 col 29: Undefined name '_notifica'.

line 18 col 41: The method 'tionEvent' isn't defined for the class 'StreamNotifications'.

line 18 col 41: Expected to find ','.

line 18 col 51: Undefined name 'event'.

Document public APIs. (-1 points)

15 out of 15 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.

Maintenance suggestions

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.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 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