Last active
February 14, 2020 00:00
-
-
Save legalcodes/e58726eb022b37ec717a3da5a4c00138 to your computer and use it in GitHub Desktop.
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
import 'package:flutter/material.dart'; | |
import 'package:flutter/cupertino.dart'; | |
void main() async { | |
runApp( | |
MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: MyApp(), | |
), | |
), | |
); | |
} | |
class MyApp extends StatelessWidget { | |
static const String _title = 'Flutter Code Sample'; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: _title, | |
home: MyStatefulWidget(), | |
); | |
} | |
} | |
class MyStatefulWidget extends StatefulWidget { | |
MyStatefulWidget({Key key}) : super(key: key); | |
@override | |
_MyStatefulWidgetState createState() => _MyStatefulWidgetState(); | |
} | |
class _MyStatefulWidgetState extends State<MyStatefulWidget> { | |
Future<String> _calculation = Future<String>.delayed( | |
Duration(seconds: 2), | |
() => 'Data Loaded', | |
); | |
Widget build(BuildContext context) { | |
return FutureBuilder<String>( | |
future: _calculation, // a previously-obtained Future<String> or null | |
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { | |
List<Widget> children; | |
if (snapshot.hasData) { | |
children = <Widget>[ | |
Icon( | |
Icons.check_circle_outline, | |
color: Colors.green, | |
size: 60, | |
), | |
Padding( | |
padding: const EdgeInsets.only(top: 16), | |
child: Text('Result: ${snapshot.data}'), | |
) | |
]; | |
} else if (snapshot.hasError) { | |
children = <Widget>[ | |
Icon( | |
Icons.error_outline, | |
color: Colors.red, | |
size: 60, | |
), | |
Padding( | |
padding: const EdgeInsets.only(top: 16), | |
child: Text('Error: ${snapshot.error}'), | |
) | |
]; | |
} else { | |
children = <Widget>[ | |
// const Padding( | |
// padding: EdgeInsets.only(top: 300), | |
// child: CupertinoActivityIndicator( | |
CupertinoActivityIndicator( | |
// radius: 50 | |
animating: false | |
// ), | |
) | |
]; | |
} | |
return Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: children, | |
), | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment