Untitled
unknown
plain_text
a year ago
1.3 kB
11
Indexable
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 const CircularProgressIndicator(); default: return Center(child: Text(snapshot.data)); } }, ), ], ), ); } Future<String> _fetchData() async { await Future.delayed(const Duration(seconds: 2)); return 'Some Asynchronous Data!'; } }
Editor is loading...
Leave a Comment