Skip to content

Commit c623c82

Browse files
update
1 parent fe1a7a3 commit c623c82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2653
-925
lines changed

projects/flutter-demo/README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
# flutter_demo
1+
# 目录结构说明
2+
3+
> **【说明】** 请运行``all_samples`目录里面的`main_page.dart`文件,重点关注`all_samples`目录。
4+
5+
### main_page 是 首页,点击它里面的3个按钮,分别跳到normal_page页面,router目录,list目录
6+
7+
### normal_page 是创建工程时的默认页面
8+
9+
### list 表示ListView的各种用法的demo。
10+
11+
### router 是 路由的使用demo,主要演示页面如何跳转和返回。
12+
13+
**其他的dart文件写的很凌乱,后期会系统的整理到`all_samples`目录中。**
214

3-
A new Flutter application.
415

5-
## Getting Started
616

7-
For help getting started with Flutter, view our online
8-
[documentation](https://flutter.io/).
Loading
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import 'package:flutter/material.dart';
2+
3+
void main() {
4+
runApp(
5+
new MaterialApp(
6+
title: 'ListView的使用',
7+
theme: new ThemeData(
8+
primarySwatch: Colors.blue, //设置全局主题
9+
),
10+
home: new ListViewDemo(),
11+
),
12+
);
13+
}
14+
15+
class ListViewDemo extends StatelessWidget {
16+
@override
17+
Widget build(BuildContext context) {
18+
return new Scaffold(
19+
appBar: new AppBar(
20+
title: new Text('ListView的使用'),
21+
),
22+
body: new GestureDetector(
23+
onTap: () {
24+
print('点击了item!');
25+
},
26+
child: buildListItem4()),
27+
);
28+
}
29+
30+
// 自定义可折叠的列表
31+
Widget buildListItem4() {
32+
return new ListView.builder(
33+
itemBuilder: (BuildContext context, int index) =>
34+
new EntryItem(data[index]),
35+
itemCount: data.length,
36+
);
37+
}
38+
}
39+
40+
/////////////////////////////////////
41+
//// 以下是可折叠展开的ListView的demo
42+
/////////////////////////////////////
43+
class EntryItem extends StatelessWidget {
44+
const EntryItem(this.entry);
45+
46+
final Entry entry;
47+
48+
@override
49+
Widget build(BuildContext context) {
50+
return _buildTiles(entry);
51+
}
52+
53+
Widget _buildTiles(Entry root) {
54+
if (root.children.isEmpty) {
55+
return new ListTile(title: new Text(root.title)); //这个只是显示一个标题
56+
}
57+
return new ExpansionTile(
58+
//这个可以展开折叠视图
59+
key: new PageStorageKey<Entry>(root),
60+
title: new Text(root.title),
61+
children: root.children.map(_buildTiles).toList(),
62+
);
63+
}
64+
}
65+
66+
/// 应用程序显示的整个多级列表
67+
final List<Entry> data = <Entry>[
68+
new Entry(
69+
'Chapter 1',
70+
<Entry>[
71+
new Entry(
72+
' Section 1-1',
73+
<Entry>[
74+
new Entry(' Item 1-1-1'),
75+
new Entry(' Item 1-1-2'),
76+
new Entry(' Item 1-1-3'),
77+
],
78+
),
79+
new Entry(' Section 1-2'),
80+
new Entry(' Section 1-3'),
81+
],
82+
),
83+
new Entry(
84+
'Chapter 2',
85+
<Entry>[
86+
new Entry(' Section 2-1'),
87+
new Entry(' Section 2-2'),
88+
],
89+
),
90+
new Entry(
91+
'Chapter 3',
92+
<Entry>[
93+
new Entry(' Section 3-1'),
94+
new Entry(' Section 3-2'),
95+
new Entry(
96+
' Section 3-3',
97+
<Entry>[
98+
new Entry(' Item 3-3-1'),
99+
new Entry(' Item 3-3-2'),
100+
new Entry(' Item 3-3-3'),
101+
new Entry(' Item 3-3-4'),
102+
],
103+
),
104+
],
105+
),
106+
];
107+
108+
/// 应用程序显示的多级列表中的一个条目
109+
class Entry {
110+
Entry(this.title, [this.children = const <Entry>[]]);
111+
112+
final String title;
113+
final List<Entry> children;
114+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:fluttertoast/fluttertoast.dart';
3+
4+
import 'listview_customscrollview.dart';
5+
import 'listview_dividers.dart';
6+
import 'listview_gridview.dart';
7+
import 'listview_horizontal.dart';
8+
import 'listview_listtitle.dart';
9+
import 'listview_longlist.dart';
10+
import 'listview_multi_item.dart';
11+
import 'listview_multi_level.dart';
12+
import 'listview_radio_listtitle.dart';
13+
import 'listview_simple.dart';
14+
import 'listview_sliver.dart';
15+
16+
class ListViewDemos extends StatelessWidget {
17+
@override
18+
Widget build(BuildContext context) {
19+
List<Widget> widgets = <Widget>[
20+
buildClicks(
21+
buildContents('简单ListViewDemo'), context, new ListViewSimpleDemo()),
22+
buildClicks(
23+
buildContents('ListView带分割线'), context, new ListViewDividerDemo()),
24+
buildClicks(buildContents('ListView.builder构建长列表'), context,
25+
new ListViewLongListDemo()),
26+
buildClicks(
27+
buildContents('横向ListView'), context, new ListViewHorizontalDemo()),
28+
buildClicks(
29+
buildContents('ListTile的使用'), context, new ListViewListTileDemo()),
30+
buildClicks(buildContents('ListView的RadioListTile的切换'), context,
31+
new RadioListTileDemo()),
32+
buildClicks(buildContents('使用CustomScrollView创建列表'), context,
33+
new ListViewCustomScrollViewDemo()),
34+
buildClicks(
35+
buildContents('创建GridView列表'), context, new ListViewGridViewDemo()),
36+
buildClicks(buildContents('可折叠的AppBar+ListView'), context,
37+
new ListViewSliverDemo()),
38+
buildClicks(buildContents('多条目的ListView的demo'), context,
39+
new ListViewMultiItemDemo()),
40+
buildClicks(
41+
buildContents('多级列表Demo'), context, new ListViewMultiLevelDemo()),
42+
new Text(''),
43+
];
44+
45+
return new Scaffold(
46+
appBar: new AppBar(
47+
leading: new IconButton(
48+
icon: new Icon(Icons.keyboard_arrow_left),
49+
onPressed: () {
50+
print('返回首页');
51+
// 返回上一个页面
52+
Navigator.of(context).pop();
53+
}),
54+
title: new Text('ListView用法Demo'),
55+
),
56+
body: new ListView(children: widgets),
57+
);
58+
}
59+
60+
Widget buildClicks(Widget child, BuildContext context, Widget page) {
61+
return new InkWell(
62+
child: child,
63+
onTapDown: (details) {
64+
print('onTapDown');
65+
Fluttertoast.showToast(
66+
msg: 'onTapDown',
67+
toastLength: Toast.LENGTH_SHORT,
68+
gravity: ToastGravity.BOTTOM);
69+
// 发送路由消息
70+
Navigator.push(context,
71+
new MaterialPageRoute(builder: (BuildContext context) => page));
72+
},
73+
onTap: () {
74+
Fluttertoast.showToast(
75+
msg: 'onTap',
76+
toastLength: Toast.LENGTH_SHORT,
77+
gravity: ToastGravity.BOTTOM);
78+
},
79+
onLongPress: () {
80+
Fluttertoast.showToast(
81+
msg: 'onLongPress',
82+
toastLength: Toast.LENGTH_SHORT,
83+
gravity: ToastGravity.BOTTOM);
84+
},
85+
onDoubleTap: () {
86+
Fluttertoast.showToast(
87+
msg: 'onDoubleTap',
88+
toastLength: Toast.LENGTH_SHORT,
89+
gravity: ToastGravity.BOTTOM);
90+
},
91+
);
92+
}
93+
94+
Widget buildContents(var text) {
95+
return new Container(
96+
margin: new EdgeInsets.all(5.0),
97+
padding: new EdgeInsets.all(5.0),
98+
alignment: Alignment.center,
99+
constraints: new BoxConstraints.expand(height: 40.0),
100+
decoration: new BoxDecoration(
101+
color: Colors.teal[300],
102+
borderRadius: new BorderRadius.all(
103+
//让矩形四个角都变成圆角
104+
const Radius.circular(8.0),
105+
),
106+
// 阴影
107+
boxShadow: <BoxShadow>[
108+
new BoxShadow(
109+
color: Colors.teal[100],
110+
offset: new Offset(0.0, 5.0),
111+
blurRadius: 8.0,
112+
),
113+
new BoxShadow(
114+
color: Colors.grey,
115+
offset: new Offset(0.0, 6.0),
116+
blurRadius: 8.0,
117+
),
118+
],
119+
),
120+
child: buildButton(text),
121+
);
122+
}
123+
124+
Widget buildButton(var text) {
125+
return new Text(
126+
text,
127+
style: new TextStyle(
128+
color: Colors.white,
129+
fontSize: 16.0,
130+
),
131+
);
132+
}
133+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import 'package:flutter/material.dart';
2+
3+
void main() {
4+
runApp(
5+
new MaterialApp(
6+
title: 'CustomScrollView创建一个列表',
7+
theme: new ThemeData(
8+
primarySwatch: Colors.blue, //设置全局主题
9+
),
10+
home: new ListViewCustomScrollViewDemo(),
11+
),
12+
);
13+
}
14+
15+
class ListViewCustomScrollViewDemo extends StatelessWidget {
16+
@override
17+
Widget build(BuildContext context) {
18+
return new Scaffold(
19+
appBar: new AppBar(
20+
leading: new IconButton(
21+
icon: new Icon(Icons.keyboard_arrow_left),
22+
onPressed: () {
23+
// 返回上一个页面
24+
Navigator.of(context).pop();
25+
}),
26+
title: new Text(
27+
'CustomScrollView创建一个列表',
28+
style: new TextStyle(fontSize: 17.0),
29+
),
30+
),
31+
body: new GestureDetector(
32+
onTap: () {
33+
print('点击了item!');
34+
},
35+
child: buildListItem()),
36+
);
37+
}
38+
39+
// 使用CustomScrollView创建一个列表
40+
Widget buildListItem() {
41+
return new CustomScrollView(
42+
shrinkWrap: true,
43+
slivers: <Widget>[
44+
new SliverPadding(
45+
padding: const EdgeInsets.all(20.0),
46+
sliver: new SliverList(
47+
delegate: new SliverChildListDelegate(
48+
<Widget>[
49+
buildContents('item1'),
50+
new Divider(height: 1.0, color: Colors.grey),
51+
buildContents('item2'),
52+
new Divider(height: 1.0, color: Colors.grey),
53+
buildContents('item3'),
54+
new Divider(height: 1.0, color: Colors.grey),
55+
buildContents('item4'),
56+
new Divider(height: 1.0, color: Colors.grey),
57+
buildContents('item4'),
58+
new Divider(height: 1.0, color: Colors.grey),
59+
buildContents('item5'),
60+
new Divider(height: 1.0, color: Colors.grey),
61+
buildContents('item6'),
62+
new Divider(height: 1.0, color: Colors.grey),
63+
buildContents('item7'),
64+
new Divider(height: 1.0, color: Colors.grey),
65+
buildContents('item8'),
66+
new Divider(height: 1.0, color: Colors.grey),
67+
buildContents('item9'),
68+
new Divider(height: 1.0, color: Colors.grey),
69+
buildContents('item10'),
70+
],
71+
),
72+
),
73+
),
74+
],
75+
);
76+
}
77+
}
78+
79+
Widget buildContents(var text) {
80+
return new Container(
81+
alignment: Alignment.centerLeft,
82+
constraints: new BoxConstraints.expand(height: 56.0),
83+
child: new Text(text),
84+
);
85+
}

0 commit comments

Comments
 (0)