1+ import 'package:flutter/material.dart' ;
2+
3+ class Index extends StatefulWidget {
4+ @override
5+ _IndexState createState () => _IndexState ();
6+ }
7+
8+ class _IndexState extends State <Index > {
9+ var direction = Axis .horizontal;
10+ var directionValue = 'horizontal' ;
11+ var verticalDirection = VerticalDirection .down;
12+ var verticalDirectionValue = 'down' ;
13+ var spacing = 10.0 ;
14+ var runSpacing = 10.0 ;
15+
16+ @override
17+ Widget build (BuildContext context) {
18+ return Scaffold (
19+ appBar: AppBar (title: Text ('Wrap' ),),
20+ body: ListView (
21+ children: < Widget > [
22+ SizedBox (
23+ child: Text ('点击下面值查看变化' ),
24+ ),
25+ Wrap (
26+ alignment: WrapAlignment .center,
27+ children: < Widget > [
28+ FlatButton (
29+ child: Text ('direction:$directionValue ' , style: TextStyle (fontSize: 11.0 ),),
30+ onPressed: (){
31+ setState (() {
32+ direction == Axis .horizontal ? direction = Axis .vertical : direction = Axis .horizontal;
33+ directionValue == 'horizontal' ? directionValue = 'vertical' : directionValue = 'horizontal' ;
34+ });
35+ },
36+ ),
37+ FlatButton (
38+ child: Text ('verticalDirection:$verticalDirectionValue ' , style: TextStyle (fontSize: 11.0 ),),
39+ onPressed: (){
40+ setState (() {
41+ verticalDirection == VerticalDirection .up ? verticalDirection = VerticalDirection .down : verticalDirection = VerticalDirection .up;
42+ verticalDirectionValue == 'up' ? verticalDirectionValue = 'down' : verticalDirectionValue = 'up' ;
43+ });
44+ },
45+ ),
46+ FlatButton (
47+ child: Text ('spacing:$spacing ' , style: TextStyle (fontSize: 13.0 ),),
48+ onPressed: (){
49+ setState (() {
50+ spacing == 10 ? spacing = 15 : spacing = 10 ;
51+ });
52+ },
53+ ),
54+ FlatButton (
55+ child: Text ('runSpacing:$runSpacing ' , style: TextStyle (fontSize: 13.0 ),),
56+ onPressed: (){
57+ setState (() {
58+ runSpacing == 10 ? runSpacing = 15 : runSpacing = 10 ;
59+ });
60+ },
61+ )
62+ ],
63+ ),
64+ Container (
65+ width: double .infinity,
66+ height: 200 ,
67+ color: Theme .of (context).primaryColor,
68+ child: Wrap (
69+ direction: direction,
70+ alignment: WrapAlignment .center,
71+ spacing: spacing,
72+ runAlignment: WrapAlignment .center,
73+ runSpacing: runSpacing,
74+ crossAxisAlignment: WrapCrossAlignment .start,
75+ textDirection: TextDirection .ltr,
76+ verticalDirection: verticalDirection,
77+ children: List .generate (7 , (index) {
78+ return Chip (
79+ avatar: CircleAvatar (
80+ backgroundColor: Theme .of (context).primaryColor,
81+ child: Text ('E' , style: TextStyle (fontSize: 20.0 ),),
82+ ),
83+ label: Text ('Efox$index ' ),
84+ );
85+ })
86+ ),
87+ )
88+ ],
89+ )
90+ );
91+ }
92+ }
0 commit comments