am_state 0.0.4 copy "am_state: ^0.0.4" to clipboard
am_state: ^0.0.4 copied to clipboard

A state-management and data providing library. this lib gives (AmDataProvider<T>) as data provider and (AmRefreshWidget<T>) as wrapper to widgets.

GitHub contributors GitHub issues GitHub forks GitHub stars GitHub license

am_state #

A state-management and data providing library. (Fast - Safe - Easy)

This lib gives (AmDataProvider<T>) as data provider and (AmRefreshWidget<T>) as wrapper to the widgets that must be changed when provider data changed. #

Getting Started: #

To import am_state: #

import 'package:am_state/am_state.dart';

To initialize data provider: #

final dataProvider = AmDataProvider<int>(
  initialData: 0,
  providerId: 'providerId',
);
dataProvider.initialize;  // you need to use this if you want to access the provider with its id instead of its name at first time.

// OR
final dataProvider = AmDataProvider<int>();  
// You can't access this with id and dying if disposed.
// You can only access this with its name ex:[dataProvider] if still alive.
// if you added a providerId the provider won't die.

To get data anywhere after initializing the provider: #

int? num = AmDataProvider<int>.of('providerId').data;

To Refresh widgets if data changed: #

class Example extends StatelessWidget {
  const Example({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: AmRefreshWidget<int>(
        amDataProvider: AmDataProvider<int>.of('providerId'),
        builder: (ctx, value) {
          return Text('$value');
        },
      ),
    );
  }
}

Note: you could use one provider for multiple (AmRefreshWidget)s #

To change the provider data without refresh states: #

    
    dataProvider.silentDataSet = dataProvider.data! + 1;
    // OR
    AmDataProvider<String>.of('providerId').silentDataSet = 'any data';

To change provider data with refresh states: #


    dataProvider.data = dataProvider.data! + 1;
    // OR
    AmDataProvider<String>.of('providerId').data = 'Some Data';

To instantinously excute some code and then refresh states: #


    dataProvider.activeFunction = () {
      //...Some Code....instantinously invoked then states refreshed
    };
    // OR
    AmDataProvider<String>.of('providerId').activeFunction = () {
      //...Some Code....instantinously invoked then states refreshed
    };

To initialize function trigger: #

final listener = AmFunctionTrigger<int>(
  amDataProvider: AmDataProvider<int>.of('providerId'),
  function: (value){ ... some code ... }
);
listener.start;   // You need to use this line anywhere 

To cancel function trigger listening: #

listener.cancel();

To reactivate the listener: #

listener.activate();

Please star my repo and follow me 😍 #

https://github.com/AmrMAM/FlutterPackage_am_state

#

MIT LICENCE

12
likes
150
pub points
0%
popularity

Publisher

unverified uploader

A state-management and data providing library. this lib gives (AmDataProvider<T>) as data provider and (AmRefreshWidget<T>) as wrapper to widgets.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on am_state