flutter_observer 1.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • new50

flutter_observer #

android BroadcastReceiver iOS NSNotification

Supported Platforms

  • Android
  • iOS

How to Use #

# add this line to your dependencies
flutter_observer: ^1.0.6
import 'package:flutter_observer/Observable.dart';
import 'package:flutter_observer/Observer.dart';
///Accept notification page
class APageState extends State<APage> with Observer{
  @override
    void initState() {
      Observable.instance.addObserver(this);
      super.initState();
    }
 @override
  void dispose() {
    Observable.instance.removeObserver(this);
    super.dispose();
  }
  @override
   update(Observable observable,String notifyName, Map map) {
    ///do your work
      if(map != null && map.containsKey("background")){
        MaterialColor bc = map["background"];
      }else if(map != null && map.containsKey("notifyText")){
        String notifyText = map["notifyText"];
      }else{
        print("通知所有Observer");
      }
      setState(() {
      });
    }
}

///Send notification page
class CPage extends StatefulWidget {
 @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          Container(height: 100, child: Center(child: Text("C页面,负责发送通知"))),
          RaisedButton(
              onPressed: () {
                ///Called where you need to send a notification
                Map map = Map();
                map["background"] = Colors.green;
                ///Observable.instance.notifyObservers(null);
                Observable.instance.notifyObservers([
                  "APageState",
                ], notifyName : "可以通过notifyName判断通知",map: map);
              },
              child: Text("只发送通知到APageState修改背景色")),
        ],
      ),
    );
  }
}

Observable propertydescription
stateNamesList or null
map{"id":"1"}

[1.0.6]

  • Optimize the addition logic of the observable

[1.0.5]

  • Increase notification name

[1.0.4]

  • modify doc

[1.0.3]

  • modify updata(Observable observable, Map map) to update(Observable observable, Map map)

[1.0.2]

  • Support Android iOS

[1.0.1]

  • Initial Open Sources
  • Support Android iOS

example/README.md

example #

A new Flutter project.

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:
  flutter_observer: ^1.0.6

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:flutter_observer/Observable.dart';
import 'package:flutter_observer/Observer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

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

  • Dart: 2.6.0
  • 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/Observable.dart.

Run flutter format to format lib/Observable.dart.

Format lib/Observer.dart.

Run flutter format to format lib/Observer.dart.

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.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test