Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sharmadhiraj
Created August 9, 2018 10:04
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 sharmadhiraj/8eaf579fafa6d5521b2694575bd50bd4 to your computer and use it in GitHub Desktop.
Save sharmadhiraj/8eaf579fafa6d5521b2694575bd50bd4 to your computer and use it in GitHub Desktop.
Base StatefulWidget
abstract class BaseStatefulWidget extends StatefulWidget {
String getTitle();
Widget body(AsyncSnapshot snapshot);
Future future();
@override
State<StatefulWidget> createState() => BaseState(getTitle());
}
class BaseState extends State<BaseStatefulWidget> {
final String title;
BaseState(this.title);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: FutureBuilder(
future: widget.future(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
return snapshot.connectionState == ConnectionState.done
? snapshot.hasData
? widget.body(snapshot)
: InkWell(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Text("Failed to connect ! Tap to retry !!"),
),
onTap: () => setState(() {}),
)
: Center(child: CircularProgressIndicator());
},
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment