stateprovider 0.5.0 copy "stateprovider: ^0.5.0" to clipboard
stateprovider: ^0.5.0 copied to clipboard

outdated

A lightweight StateProvider for handling global data. This Plugin wraps an InheritedWidget into a StreamBuilder for updating the UI if any changes appears in the InheritedWidget.

StateProvider for Flutter #

A lightweight StateProvider for handling global data. This Plugin wraps an InheritedWidget into a StreamBuilder for updating the UI if any changes appears in the InheritedWidget.

Getting Started #

1. Import stateprovider

import 'package:stateprovider/stateprovider.dart';

2. Create a Model which extends the Store class. Add your custom attributes and functions. Call notify() in every function where you want to update the state.

class MyModel extends Store<MyModel> {

  String name = "";
  int age = 0; 

  //stores only the new data but doesn't update the ui
  void setName(String name) {
    this.name = name;
  } 

  //updates the ui because of notify()
  void setAge(int age) {
    this.index = index;
    notify();
  }

}

3. Add the StatefulProvider widget in the SECOND position of your tree under MaterialApp or CupertinoApp. Add your custom Model to the StatefulProvider.

void main() => runApp(
  MaterialApp(
    home: StatefulProvider(
      store: MyModel(),
      child: PageOne(),
    ),
  )
);

4. Now inside your widget you can use your data with the StateProvider class: #

StateProvider.of(context).getState<MyModel>().setAge(34)

Additional #

if you want to update the state manually use:

StateProvider.of(context).getState<MyModel>().notify()
0
likes
0
pub points
17%
popularity

Publisher

verified publisheronurozkan.net

A lightweight StateProvider for handling global data. This Plugin wraps an InheritedWidget into a StreamBuilder for updating the UI if any changes appears in the InheritedWidget.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on stateprovider