Skip to content

Instantly share code, notes, and snippets.

@techpotatoes
Created April 18, 2020 14:31
Show Gist options
  • Save techpotatoes/92b5de77510c36d41400bb41a9137fd8 to your computer and use it in GitHub Desktop.
Save techpotatoes/92b5de77510c36d41400bb41a9137fd8 to your computer and use it in GitHub Desktop.
Flutter development series - part4
class LoyaltyListPage extends StatefulWidget {
LoyaltyListPage({Key key}) : super(key: key);
@override
_LoyaltyListPageState createState() => _LoyaltyListPageState();
}
class _LoyaltyListPageState extends State<LoyaltyListPage> {
@override
void initState() {
super.initState();
BlocProvider.of<LoyaltyBloc>(context).add(Fetch());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Loyalty"),
),
body: Container(
child:
BlocBuilder<LoyaltyBloc, LoyaltyState>(builder: (_, state) {
switch (state.runtimeType) {
case LoyaltyEmpty:
return _EmptyWidget();
break;
case LoyaltyLoading:
return CircularProgressIndicator();
break;
case LoyaltyError:
return _ErrorWidget();
break;
case LoyaltyLoaded:
return _LoadedWidget(loyaltyCards: state.props.first);
break;
default:
return _ErrorWidget();
}
}),
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment