notify_state 1.0.1

notify_state #

  • State sharing management of business objects.

Using #

  • use NotifyObject with ChangeNotifier
  • use StatefulWidget extends NotifyWidget
  • use State extends NotifyState
class TestWidget extends NotifyWidget {
  TestWidget({Key key, @required ChangeNotifier notifier}):super(key: key, notifier:notifier);
  @override
  _TestWidgetState createState() => new _TestWidgetState();
}

class _TestWidgetState extends NotifyState {
}
  • demo:
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class TestNotify with ChangeNotifier {
  num _counter = 0;
  num get counter => _counter;
  set counter(num v) {
    _counter = v;
    notifyListeners();
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(
        title: 'Flutter Demo',
        data: new TestNotify(),
      ),
    );
  }
}

class HomePage extends StatefulWidget {
  HomePage({Key key, this.title, this.data}) : super(key: key);

  final TestNotify data;
  final String title;

  @override
  _HomePageState createState() => new _HomePageState();
}

class _HomePageState extends State<HomePage> {
  TestNotify data;
  @override
  void initState() {
    super.initState();
    this.data = widget.data;
  }

  void _incrementCounter() {
    data.counter++;
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new TestWidget(notifier:data),
      floatingActionButton: new FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ),
    );
  }
}

class TestWidget extends NotifyWidget {
  TestWidget({Key key, @required ChangeNotifier notifier}):super(key: key, notifier:notifier);
  @override
  _TestWidgetState createState() => new _TestWidgetState();
}

class _TestWidgetState extends NotifyState {
  @override
  Widget build(BuildContext context) {
    return new Center(
      child: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          new Text(
            'You have pushed the button this many times:',
          ),
          new Text(
            '${(notifier as TestNotify).counter}',
            style: Theme.of(context).textTheme.display1,
          ),
        ],
      ),
    );
  }
}

[0.0.1] - Jul 1, 2019.

  • frist release.

[0.0.2] - TJul 17, 2019.

  • add example .

[1.0.0] - TJul 17, 2019.

  • description.

[1.0.1] - TJul 17, 2019.

  • format.

example/README.md

notify_state #

  • State sharing management of business objects.

Using #

  • use NotifyObject with ChangeNotifier
  • use StatefulWidget extends NotifyWidget
  • use State extends NotifyState
class TestWidget extends NotifyWidget {
  TestWidget({Key key, @required ChangeNotifier notifier}):super(key: key, notifier:notifier);
  @override
  _TestWidgetState createState() => new _TestWidgetState();
}

class _TestWidgetState extends NotifyState {
}
  • demo:
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class TestNotify with ChangeNotifier {
  num _counter = 0;
  num get counter => _counter;
  set counter(num v) {
    _counter = v;
    notifyListeners();
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(
        title: 'Flutter Demo',
        data: new TestNotify(),
      ),
    );
  }
}

class HomePage extends StatefulWidget {
  HomePage({Key key, this.title, this.data}) : super(key: key);

  final TestNotify data;
  final String title;

  @override
  _HomePageState createState() => new _HomePageState();
}

class _HomePageState extends State<HomePage> {
  TestNotify data;
  @override
  void initState() {
    super.initState();
    this.data = widget.data;
  }

  void _incrementCounter() {
    data.counter++;
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new TestWidget(notifier:data),
      floatingActionButton: new FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ),
    );
  }
}

class TestWidget extends NotifyWidget {
  TestWidget({Key key, @required ChangeNotifier notifier}):super(key: key, notifier:notifier);
  @override
  _TestWidgetState createState() => new _TestWidgetState();
}

class _TestWidgetState extends NotifyState {
  @override
  Widget build(BuildContext context) {
    return new Center(
      child: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          new Text(
            'You have pushed the button this many times:',
          ),
          new Text(
            '${(notifier as TestNotify).counter}',
            style: Theme.of(context).textTheme.display1,
          ),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  notify_state: ^1.0.1

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:notify_state/notify_state.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
21
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]
60
Learn more about scoring.

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

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

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