asyncstate 0.0.2 copy "asyncstate: ^0.0.2" to clipboard
asyncstate: ^0.0.2 copied to clipboard

outdated

This package will help you to call a loading in your async methods very easyly, and you don't need to worrie when it's is starting or finishing.

Async State

Platform


Where this package works! #

[x] Android
[x] IOS
[x] Web
[x] Macos
[-] Linux (not tested yet)
[-] Windows (not tested yet)

Usage #

AsyncState:

void main() {
  AsyncState.onInitAsyncState(
    defaultDialogWidget:
        const Center(child: CircularProgressIndicator())
,       /// It will give you a default loading for every loading transaction
  );
  runApp(const MyApp());
}         

Difine your Widget with Loading default.


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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      themeMode: ThemeMode.dark,
      navigatorObservers: [
        AsyncState.observer //This observer is important to get the context yo use the dialogs
      ], 
      theme: ThemeData.dark(),
      home: HomePage(),
    );
  }
}

Add "AsyncState.observer" on MaterialApp.

Using as Mixin in your controller (callAsyncLoader()) #

class HomeController with AsyncStateMixin {
  
  Future goBack(Function callback) async {
    return await callAsyncLoader(
      Future.delayed(
        const Duration(seconds: 3),
        () {
          callback();
        },
      ),
    );
  }
}

Use as an extension anywhere (.asyncLoader()) #

class HomeController{

   Future<bool> login() async {
    try {
      return await Future.delayed(const Duration(seconds: 3), () {
        return true;
      }).asyncLoader(
          customLoader: const MyCustomLoadingWidget(
        text: 'Sign in! Hold on!!!!',
      ));
    } catch (e) {
      // debugPrint(e.toString());
      return false;
    }
  }
}

Call in your View like this #

ElevatedButton(
            onPressed: () async {
              if (await controller.login()) { 
                ///Use a Navigator to go to another page if your login is true
                ///You don't need to care about start of finish the loading, just what to do after or before!
                Navigator.push(
                  context,
                  MaterialPageRoute(
                      builder: (context) => SecondPage(
                            controller: controller,
                          )),
                );
              }
            },
            child: const Text('Sign in!'),
          )

Bugs or Requests #

If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket on GitHub and I'll look into it. Pull request are also welcome.

Contributors #


Leonardo Serrano


Marcus Brasizza

If you like what I do, maybe consider buying me a coffee/tea πŸ₯ΊπŸ‘‰πŸ‘ˆ

Buy Me A Coffee

48
likes
0
pub points
92%
popularity

Publisher

verified publisherleonardoserrano.dev

This package will help you to call a loading in your async methods very easyly, and you don't need to worrie when it's is starting or finishing.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on asyncstate