Skip to content

Instantly share code, notes, and snippets.

@pseudo-su
Created January 7, 2019 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pseudo-su/1279097eb00a797209fe10741c735015 to your computer and use it in GitHub Desktop.
Save pseudo-su/1279097eb00a797209fe10741c735015 to your computer and use it in GitHub Desktop.
class SplashWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SplashStateProvider( // InheritedWidget
builder: (context, snapshot) {
final SplashState splashState = SplashState.of(context);
if (splashState.snapshot.isLoading) {
return Center(
// instead of the LoadingUI widget knowing about how to subscribe to items, we should be able to
// instead pass the already resolved items down the widget tree.
child: Loading(items: splashState.snapshot.items)
);
}
return Center(child: LoadingFinished());
}
);
}
}
class Loading extends StatelessWidget {
@override
Widget build(items) { /* not exactly sure how you pass down values directly to widgets */
return Flexible(
flex: 2,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: items.map((item) {
var loadText = '';
switch (item.status) {
case LoadingStatus.loading:
loadText = 'Loading...';
break;
case LoadingStatus.loaded:
loadText = '✔️';
break;
default:
loadText = '';
}
return Text('${item.description}: $loadText');
}).toList(),
);
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment