asyncstate 0.0.5 icon indicating copy to clipboard operation
asyncstate: ^0.0.5 copied to clipboard

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


iOS Android Mac Linux Windows


Usage #

AsyncState:

void main() {
  AsyncState.setLoaderPersonalized(
    defaultLoaderWidget: const MyLoading(),
    /// Here you can customize your default loading that will show every transaction
    /// Leave it and it will show a simple CircularProgress indicator
  );
  runApp(const MyApp());
}      

Define 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

8
likes
130
pub points
40%
popularity

Publisher

verified publisher iconleonardoserrano.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)

Documentation

API reference

License

Icon for licenses.BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on asyncstate