Created
January 10, 2022 20:51
-
-
Save erickzanardo/c67e7cb6707af33b0bd11e3b7d9b95d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp(home: Home()); | |
} | |
} | |
class Home extends StatefulWidget { | |
@override | |
_HomeState createState() => _HomeState(); | |
} | |
class _HomeState extends State<Home> { | |
var _switchValue = false; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Switch( | |
value: _switchValue, | |
onChanged: (newValue) { | |
setState(() => _switchValue = newValue); | |
}, | |
), | |
FutureBuilder( | |
future: _fetchData(), | |
builder: (context, AsyncSnapshot snapshot) { | |
switch (snapshot.connectionState) { | |
case ConnectionState.none: | |
case ConnectionState.waiting: | |
return Center(child: CircularProgressIndicator()); | |
default: | |
return Center(child: Text(snapshot.data)); | |
} | |
}, | |
), | |
], | |
), | |
); | |
} | |
Future<String> _fetchData() async { | |
await Future.delayed(Duration(seconds: 2)); | |
return 'Some Asynchronous Data!'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment