s_provider 1.0.0

Flutter Android iOS web

Flutter state management package. The most basic form of provider. It takes a value and exposes it, whatever the value is..

static_provider #

Flutter state management package.

Usage #


Extend StaticChangeNotifier class #

class CountStaticProvider extends StaticChangeNotifier {
  int count = 0;

  add() {
    count++;
    notifyListeners();
  }

  remove() {
    count--;
    notifyListeners();
  }
}

Create new instance #

StaticProvider.addProvider(CountStaticProvider());

Get the instance #

CountStaticProvider provider = StaticProvider.of<CountStaticProvider>(context);

Example #

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

  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  _MyHomePageState() {
    StaticProvider.addProvider(CountStaticProvider());
  }

  @override
  void dispose() {
    StaticProvider.disposeListeners<CountStaticProvider>(context);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    CountStaticProvider provider =
        StaticProvider.of<CountStaticProvider>(context);
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '${provider.count}',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => provider.add(),
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), 
    );
  }
}

0
likes
100
pub points
0%
popularity

Flutter state management package. The most basic form of provider. It takes a value and exposes it, whatever the value is..

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

antoniosimeonovski@gmail.com

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on s_provider