notify_state 1.0.1 copy "notify_state: ^1.0.1" to clipboard
notify_state: ^1.0.1 copied to clipboard

State sharing management of business objects. Multiple statefulwidgets care about the same object, and an object property change notifies all concerned statefulwidgets to redraw

example/example.dart

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

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

class TestData extends ChangeNotifier {
  int _counter = 0;
  int get counter => _counter;
  set counter(int v) {
    this._counter = v;
    notifyListeners();
  }
}

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

class MyHomePage extends NotifyWidget {
  MyHomePage({Key key, @required ChangeNotifier notifier})
      : super(key: key, notifier: notifier);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends NotifyState {

  void _incrementCounter(){
    (notifier as TestData).counter++;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("title" + (notifier as TestData).counter.toString()),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              (notifier as TestData).counter.toString(),
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), 
    );
  }
}
0
likes
30
pub points
33%
popularity

Publisher

unverified uploader

State sharing management of business objects. Multiple statefulwidgets care about the same object, and an object property change notifies all concerned statefulwidgets to redraw

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on notify_state