Flutter Widget之Wrap

Widget:https://flutter.io/docs/development/ui/widgets
Wrap:https://docs.flutter.io/flutter/widgets/Wrap-class.html

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import 'package:flutter/material.dart';

class WrapDemoPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => new _WrapDemoPagePageState();
}

class _WrapDemoPagePageState extends State<WrapDemoPage> {
@override
void initState() {
super.initState();
}

Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text('Wrap Demo'),
),
// body: Wrap(
// spacing: 8.0, // gap between adjacent chips
// runSpacing: 4.0, // gap between lines
// children: <Widget>[
// Chip(
// avatar: CircleAvatar(backgroundColor: Colors.blue.shade900, child: Text('A')),
// label: Text('Android'),
// ),
// Chip(
// avatar: CircleAvatar(backgroundColor: Colors.blue.shade900, child: Text('I')),
// label: Text('iOS'),
// ),
// Chip(
// avatar: CircleAvatar(backgroundColor: Colors.blue.shade900, child: Text('A')),
// label: Text('AppBlog.CN'),
// ),
// Chip(
// avatar: CircleAvatar(backgroundColor: Colors.blue.shade900, child: Text('W')),
// label: Text('Windows'),
// ),
// ],
// )
body: Align(
alignment: Alignment.topCenter,
child: Wrap(
spacing: 10.0,
runSpacing: 5.0,
direction: Axis.horizontal,
alignment: WrapAlignment.start,
children: <Widget>[
MyButton("西游记"),
MyButton("三国演义"),
MyButton("红楼梦"),
MyButton("水浒传"),
MyButton("史记"),
MyButton("资治通鉴"),
MyButton("天龙八部"),
],
)),
);
}
}

class MyButton extends StatelessWidget {
final text;

MyButton(this.text);

@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(left: 3.0, right: 3.0),
child: OutlineButton(
borderSide: BorderSide(
color: Colors.blueAccent, width: 2.0, style: BorderStyle.solid),
disabledBorderColor: Colors.grey,
highlightedBorderColor: Colors.redAccent,
onPressed: () {
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text(text),
action: new SnackBarAction(
label: "撤回",
onPressed: () {},
),
));
},
child: Text(text),
));
}
}

Flutter Widget Wrap

Flutter Widget Wrap

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :