-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
54 lines (49 loc) · 1.47 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'package:flutter/material.dart';
import 'package:flutter_async_widgets/flutter_async_widgets.dart';
void main() {
runApp(const ExampleApp());
}
class ExampleApp extends StatelessWidget {
const ExampleApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'flutter_async_builder example',
theme: ThemeData(primarySwatch: Colors.blue),
home: const ExampleWidget(),
);
}
}
class ExampleWidget extends StatelessWidget {
const ExampleWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return AsyncBuilder.single<String>(
Future.delayed(
const Duration(seconds: 5), () => 'String from the future'),
builder: (context, child, data) => Scaffold(
appBar: AppBar(
title: const Text('AsyncBuilder'),
actions: [
// If data is null the future is still loading
if (data == null)
const Padding(
padding: EdgeInsets.all(16),
child: AspectRatio(
aspectRatio: 1,
child: CircularProgressIndicator(),
),
),
],
),
body: Container(
width: double.infinity,
padding: const EdgeInsets.all(24),
child: child,
),
),
onData: (context, data) =>
Center(child: Text(data, textAlign: TextAlign.center)),
);
}
}