Git Product home page Git Product logo

flutter_observer's Introduction

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 property description
stateNames List or null
map {"id":"1"}

flutter_observer's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.