Skip to content

Commit fe1a7a3

Browse files
update
1 parent ddf821b commit fe1a7a3

File tree

6 files changed

+257
-1
lines changed

6 files changed

+257
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import 'package:flutter/material.dart';
2+
3+
void main() {
4+
runApp(
5+
new MaterialApp(
6+
title: 'Demo1',
7+
theme: new ThemeData(
8+
primarySwatch: Colors.blue,
9+
),
10+
home: new Demo1(),
11+
),
12+
);
13+
}
14+
15+
class Demo1 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+
print('返回首页');
24+
// 返回上一个页面
25+
Navigator.of(context).pop();
26+
}),
27+
title: new Text('Demo1'),
28+
),
29+
body: new Center(
30+
child: new Text('hello world'),
31+
),
32+
);
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:flutter/material.dart';
2+
3+
void main() {
4+
runApp(
5+
new MaterialApp(
6+
title: 'Demo2',
7+
theme: new ThemeData(
8+
primarySwatch: Colors.blue,
9+
),
10+
home: new Demo2(),
11+
),
12+
);
13+
}
14+
15+
class Demo2 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+
print('返回首页');
24+
Navigator.of(context).pop();
25+
}),
26+
title: new Text('Demo2'),
27+
),
28+
body: new Center(
29+
child: new Text('hello world 2'),
30+
),
31+
);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:flutter/material.dart';
2+
3+
void main() {
4+
runApp(
5+
new MaterialApp(
6+
title: 'Demo3',
7+
theme: new ThemeData(
8+
primarySwatch: Colors.blue,
9+
),
10+
home: new Demo3(),
11+
),
12+
);
13+
}
14+
15+
class Demo3 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+
print('返回首页');
24+
Navigator.of(context).pop();
25+
}),
26+
title: new Text('Demo3'),
27+
),
28+
body: new Center(
29+
child: new Text('hello world 3'),
30+
),
31+
);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:flutter/material.dart';
2+
3+
void main() {
4+
runApp(
5+
new MaterialApp(
6+
title: 'Demo4',
7+
theme: new ThemeData(
8+
primarySwatch: Colors.blue,
9+
),
10+
home: new Demo4(),
11+
),
12+
);
13+
}
14+
15+
class Demo4 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+
print('返回首页');
24+
Navigator.of(context).pop();
25+
}),
26+
title: new Text('Demo4'),
27+
),
28+
body: new Center(
29+
child: new Text('hello world 4'),
30+
),
31+
);
32+
}
33+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:fluttertoast/fluttertoast.dart';
3+
4+
import 'demo1.dart';
5+
import 'demo2.dart';
6+
import 'demo3.dart';
7+
import 'demo4.dart';
8+
9+
void main() {
10+
runApp(new MaterialApp(
11+
// 路由管理,指定发送到哪个页面
12+
routes: <String, WidgetBuilder>{
13+
'/demo1': (BuildContext context) => new Demo1(),
14+
'/demo2': (BuildContext context) => new Demo2(),
15+
'/demo3': (BuildContext context) => new Demo3(),
16+
'/demo4': (BuildContext context) => new Demo4(),
17+
},
18+
title: 'demo',
19+
theme: new ThemeData(
20+
primarySwatch: Colors.blue,
21+
),
22+
home: new RouterDemo(),
23+
));
24+
}
25+
26+
class RouterDemo extends StatelessWidget {
27+
@override
28+
Widget build(BuildContext context) {
29+
List<Widget> widgets = <Widget>[
30+
buildClicks(buildContents('按钮1'), context, '/demo1'),
31+
buildClicks(buildContents('按钮2'), context, '/demo2'),
32+
buildClicks(buildContents('按钮3'), context, '/demo3'),
33+
buildClicks(buildContents('按钮4'), context, '/demo4'),
34+
];
35+
36+
return new Scaffold(
37+
appBar: new AppBar(
38+
title: new Text('demo'),
39+
),
40+
body: new Column(children: widgets),
41+
);
42+
}
43+
44+
Widget buildClicks(Widget child, BuildContext context, String routeStr) {
45+
return new InkWell(
46+
child: child,
47+
onTapDown: (details) {
48+
print('onTapDown');
49+
Fluttertoast.showToast(
50+
msg: 'onTapDown',
51+
toastLength: Toast.LENGTH_SHORT,
52+
gravity: ToastGravity.BOTTOM);
53+
// 发送路由消息
54+
Navigator.pushNamed(context, '$routeStr');
55+
},
56+
onTap: () {
57+
Fluttertoast.showToast(
58+
msg: 'onTap',
59+
toastLength: Toast.LENGTH_SHORT,
60+
gravity: ToastGravity.BOTTOM);
61+
},
62+
onLongPress: () {
63+
Fluttertoast.showToast(
64+
msg: 'onLongPress',
65+
toastLength: Toast.LENGTH_SHORT,
66+
gravity: ToastGravity.BOTTOM);
67+
},
68+
onDoubleTap: () {
69+
Fluttertoast.showToast(
70+
msg: 'onDoubleTap',
71+
toastLength: Toast.LENGTH_SHORT,
72+
gravity: ToastGravity.BOTTOM);
73+
},
74+
);
75+
}
76+
77+
Widget buildContents(var text) {
78+
return new Container(
79+
margin: new EdgeInsets.all(10.0),
80+
padding: new EdgeInsets.all(10.0),
81+
alignment: Alignment.center,
82+
constraints: new BoxConstraints.expand(height: 56.0),
83+
decoration: new BoxDecoration(
84+
color: Colors.teal[300],
85+
borderRadius: new BorderRadius.all(
86+
//让矩形四个角都变成圆角
87+
const Radius.circular(8.0),
88+
),
89+
// 阴影
90+
boxShadow: <BoxShadow>[
91+
new BoxShadow(
92+
color: Colors.teal[100],
93+
offset: new Offset(0.0, 5.0),
94+
blurRadius: 8.0,
95+
),
96+
new BoxShadow(
97+
color: Colors.grey,
98+
offset: new Offset(0.0, 6.0),
99+
blurRadius: 8.0,
100+
),
101+
],
102+
),
103+
child: buildButton(text),
104+
);
105+
}
106+
107+
Widget buildButton(var text) {
108+
return new Text(
109+
text,
110+
style: new TextStyle(
111+
color: Colors.white,
112+
fontSize: 16.0,
113+
),
114+
);
115+
}
116+
}

projects/flutter-demo/pubspec.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ dependencies:
1414
path_provider: ^0.2.1+1
1515
# 图片处理
1616
image: ^2.0.4
17+
cached_network_image: ^0.4.1+1
18+
transparent_image: ^0.1.0
19+
shared_preferences: ^0.4.2
20+
path_provider: ^0.4.1
21+
sqflite: ^0.9.0
22+
http: ^0.11.3+16
23+
dio: ^0.0.14
1724
# 弹吐司
18-
fluttertoast ^2.0.3
25+
fluttertoast: ^2.0.3
1926

2027

2128
dev_dependencies:

0 commit comments

Comments
 (0)