flutter_guards 0.0.1 copy "flutter_guards: ^0.0.1" to clipboard
flutter_guards: ^0.0.1 copied to clipboard

discontinued
outdated

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
30
pub points
0%
popularity

Publisher

unverified uploader

Contains LoadingGuard, AuthGuard, FutureGuard, StreamGuard

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_guards