flutter_guards 0.0.2
flutter_guards: ^0.0.2 copied to clipboard

Contains LoadingGuard, AuthGuard, FutureGuard, StreamGuard

flutter_guards #

Simple package containing the following guards:

  • LoadingGuard
  • AuthGuard
  • FutureGuard
  • StreamGuard

Usage #

FutureGuard and Stream guards takes buiders that will be executed on loading, on success and on data to display a widget. While the other guards take direct widgets.

LoadingGuard #

final preload = Future.delayed(Duration(seconds: 2));

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: LoadingGuard(
        load: preload,
        loading: LoadingPage(),
        success: HomePage(),
        error: ErrorPage(),
        ),
      ),
    );
  }
}

AuthGuard #

StreamController<bool> authState = StreamController();
authState.add(false);

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: AuthGuard(
              authStream: authState.stream,
              signedIn: HomePage(),
              signedOut: SignInPage(),
        ),
      ),
    );
  }
}

FutureGuard #


final future = Future.delayed(Duration(seconds: 2)).map((event) => true);
// ...

@override
Widget build(BuildContext context) {
  return FutureGuard<bool>(
    future: future,
    onData: (data) => HomePage('Future data received'),
    onLoad: () => LoadingPage(),
    onError: (e) => ErrorPage(),
  );
}

StreamGuard #

final stream = Stream.periodic(Duration(seconds: 2)).map((event) => true);

// ...

  @override
  Widget build(BuildContext context) {
    return StreamGuard<bool>(
      stream: ,
      onData: (data) => HomePage('Stream data received'),
      onLoad: () => LoadingPage(),
      onError: (e) => ErrorPage(),
    );
  }
5
likes
120
pub points
42%
popularity

Contains LoadingGuard, AuthGuard, FutureGuard, StreamGuard

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

cedvandenbosch@gmail.com

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_guards