Last active
March 8, 2020 01:31
-
-
Save lukepighetti/bebfe371f33c5480c1e02ca80e90953b to your computer and use it in GitHub Desktop.
A declarative™ way to handle loading notifications with Widgets™
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:async'; | |
| import 'package:flutter/material.dart'; | |
| import 'package:material_theme/loading_notification/loading_image.dart'; | |
| import 'package:material_theme/loading_notification/loading_notification_listener.dart'; | |
| import 'package:material_theme/widgets/layout/default_scaffold.dart'; | |
| import 'loading_future_builder.dart'; | |
| class LoadingNotificationsRoute extends StatefulWidget { | |
| @override | |
| _LoadingNotificationsRouteState createState() => | |
| _LoadingNotificationsRouteState(); | |
| } | |
| class _LoadingNotificationsRouteState extends State<LoadingNotificationsRoute> { | |
| final _groupOne = { | |
| "1000": Duration(milliseconds: 1000), | |
| "1250": Duration(milliseconds: 1250), | |
| "1500": Duration(milliseconds: 1500), | |
| "1750": Duration(milliseconds: 1750), | |
| }; | |
| bool _isLoading = true; | |
| void _handleLoaded() { | |
| print("Loaded!"); | |
| setState(() { | |
| _isLoading = false; | |
| }); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return DefaultScaffold( | |
| "/loading-notifications", | |
| child: LoadingNotificationListener( | |
| onLoaded: _handleLoaded, | |
| child: Column( | |
| children: [ | |
| Text(_isLoading ? "All still loading..." : "All done!"), | |
| SizedBox(height: 16), | |
| /// Group One | |
| LoadingNotificationListener( | |
| key: Key("Group 1"), | |
| child: Column( | |
| children: <Widget>[ | |
| Text("FutureBuilders"), | |
| ..._groupOne.entries.map<Widget>((e) { | |
| return LoadingFutureBuilder<String>( | |
| key: Key(e.key), | |
| future: | |
| Future<String>.delayed(e.value).then((_) => e.key), | |
| initialData: "Loading...", | |
| builder: (context, snap) { | |
| return Text(snap.data ?? "Wat"); | |
| }, | |
| ); | |
| }) | |
| ], | |
| ), | |
| ), | |
| SizedBox(height: 32), | |
| /// Images | |
| LoadingNotificationListener( | |
| key: Key("Images"), | |
| child: Column( | |
| children: <Widget>[ | |
| Text("Images"), | |
| LoadingImage( | |
| key: Key("Image 1"), | |
| image: NetworkImage( | |
| "https://upload.wikimedia.org/wikipedia/commons/4/4e/Pleiades_large.jpg", | |
| ), | |
| ), | |
| LoadingImage( | |
| key: Key("Image 2"), | |
| image: NetworkImage( | |
| "https://upload.wikimedia.org/wikipedia/commons/3/3d/LARGE_elevation.jpg", | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment