Created
August 9, 2018 10:04
-
-
Save sharmadhiraj/8eaf579fafa6d5521b2694575bd50bd4 to your computer and use it in GitHub Desktop.
Base StatefulWidget
This file contains 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
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