sura_manager 0.1.4 copy "sura_manager: ^0.1.4" to clipboard
sura_manager: ^0.1.4 copied to clipboard

outdated

A custom ValueNotifier and ValueListenableBuilder that support asynchronus value handling.

Sura Manager #

A custom ValueNotifier and ValueListenableBuilder that support asynchronus value handling.

pub package Latest commit

Installation #

Add this to pubspec.yaml

dependencies:
  sura_manager: ^0.1.4

FutureManager #

Property description default
futureFunction a function to run and return data null
reloading Reset a state to loading or not when you call refresh or asyncOperation true
onSuccess a callback function called after operation is success null
onDone a callback function called after operation is completely done, similar to finally in try-catch null
onError a callback function called after operation has an error null
field description
data current data in the Manager
error error in the Manager
hasData check if our Manager has a data
hasError check if our Manager has an error
future future field of the current futureFunction
Method description
when A method similar to FutureManagerBuilder
asyncOperation run futureFunction that will return a data to our Manager
refresh call the asyncOperation again. we have to assign futureFunction from the constructor or call asyncOperation once to run this method, otherwise it will log an error
updateData a method to update data in our Manager
modifyData a method to update data in our Manager with data callback, prefer using this method to update data.
resetData reset eveything to loading or null state
addError add error into our manager

FutureManagerBuilder #

Example #

class _HomePageState extends State<NewPage> {

  FutureManager<int> dataManager = FutureManager();
  @override
  void initState() {
    dataManager.asyncOperation(()async{
      await Future.delayed(Duration(seconds: 2));
      //Add 10 into our dataManager
      return 10;
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    //Use with FutureManagerBuilder
    return Scaffold(
      appBar: AppBar(
        actions: [
          IconButton(
            icon:Icon(Icons.refresh),
            onPressed:(){
              //call our asyncOperation again
              dataManager.refresh();
            },
          )
        ]
      ),
      body: FutureManagerBuilder<int>(
        futureManager: dataManager,
        error: (error) => YourErrorWidget(),
        loading: YourLoadingWidget(),
        ready: (context, data){
          //result: My data: 10
          return Text("My data: ${data}"),
        }
      ),
    );
  }
}

Documentation #

Property description default
futureManager our FutureManager object required
ready A widget builder show when [FutureManager] has a data required
loading A widget show when [FutureManager] state is loading CircularProgressIndicator
error A widget show when [FutureManager] state is error Text(error.toString())
onError A callback function that call when [FutureManager] state is error null
onReady A callback function that call when [FutureManager] state has a data null
onRefreshing A widget to show on top of this widget when refreshing null
4
likes
0
pub points
57%
popularity

Publisher

verified publisherasurraa.com

A custom ValueNotifier and ValueListenableBuilder that support asynchronus value handling.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, rxdart, sura_flutter

More

Packages that depend on sura_manager