Предоставлен базовый пример HelloWorld Flutter с включенным кодом. Я добавил задержку в будущее, чтобы ProgressIndicator показывался в течение двух секунд. Работает так, как мне предназначено:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
Map<String, bool> students;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: FutureBuilder(
future: GetInfoFromBackEnd(),
builder: (BuildContext context, AsyncSnapshot<Map> snapshot) {
return snapshot.hasData
? new Text(snapshot.data.toString())
: new CircularProgressIndicator();
}),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
Future<Map> GetInfoFromBackEnd() async {
return Future.delayed(Duration(seconds: 2), () {
students = {
'this info should be taken from backend0': false,
'this info should be taken from backend1': false,
'this info should be taken from backend2': false,
'this info should be taken from backend3': false,
'this info should be taken from backend4': false,
};
return students;
});
}
}