Skip to content

Commit 9e9a3e3

Browse files
committed
add the FutureBuilder widget
1 parent 51bbe8b commit 9e9a3e3

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

lib/const/page_item_const.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,9 @@ const PAGE_ITEMS = [
272272
"img": PageImage.FLUTTER_OPEN,
273273
"click": PageName.INTER_POINTER,
274274
},
275-
275+
{
276+
"title": PageName.ASYNC_FUTURE,
277+
"img": PageImage.FLUTTER_OPEN,
278+
"click": PageName.ASYNC_FUTURE,
279+
},
276280
];

lib/const/page_name_const.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ class PageName {
6060
static const INTER_DISMISSIBLE = "Dismissible";
6161
static const INTER_POINTER = "AbsorbPointer";
6262
static const INTER_SCROLLABLE = "Scrollable";
63+
static const ASYNC_FUTURE = "FutureBuilder";
6364
}

lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class FlutterOpenApp extends StatelessWidget {
7373
PageName.INTER_GESTURE: (context) => GesturePage(),
7474
PageName.INTER_DISMISSIBLE: (context) => DismissiblePage(),
7575
PageName.INTER_POINTER: (context) => PointerPage(),
76+
PageName.ASYNC_FUTURE: (context) => FuturePage(),
7677
},
7778
);
7879
}

lib/page/_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ export 'muti/_muti.dart';
3737
export 'assets/_assets.dart';
3838
export 'anim/_anim.dart';
3939
export 'interation/_interaction.dart';
40+
export 'async/_async.dart';

lib/page/async/FuturePage.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
///
2+
/// Created by NieBin on 2019/6/13
3+
/// Github: https://github.com/nb312
4+
/// Email: niebin312@gmail.com
5+
6+
import "package:flutter/material.dart";
7+
import "package:flutter_widgets/const/_const.dart";
8+
9+
class FuturePage extends StatefulWidget {
10+
@override
11+
_FutureState createState() => _FutureState();
12+
}
13+
14+
class _FutureState extends State<FuturePage> {
15+
Future<String> _getData() async {
16+
return "Hello world";
17+
}
18+
19+
@override
20+
Widget build(BuildContext context) {
21+
return Scaffold(
22+
appBar: AppBar(
23+
title: Text("Hello world"),
24+
),
25+
body: Container(
26+
child: FutureBuilder<String>(
27+
future: _getData(), // a previously-obtained Future<String> or null
28+
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
29+
switch (snapshot.connectionState) {
30+
case ConnectionState.none:
31+
return Text('Press button to start.');
32+
case ConnectionState.active:
33+
case ConnectionState.waiting:
34+
return Text('Awaiting result...');
35+
case ConnectionState.done:
36+
if (snapshot.hasError) return Text('Error: ${snapshot.error}');
37+
return Text('Result: ${snapshot.data}');
38+
}
39+
return RefreshIndicator(
40+
child: null, onRefresh: null); // unreachable
41+
},
42+
),
43+
),
44+
);
45+
}
46+
}

lib/page/async/_async.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
///
2+
/// Created by NieBin on 2019/6/13
3+
/// Github: https://github.com/nb312
4+
/// Email: niebin312@gmail.com
5+
///
6+
export "FuturePage.dart";

0 commit comments

Comments
 (0)