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+ List alignment = [
10+ Alignment .topLeft,
11+ Alignment .topCenter,
12+ Alignment .topRight,
13+ Alignment .centerLeft,
14+ Alignment .center,
15+ Alignment .centerRight,
16+ Alignment .bottomLeft,
17+ Alignment .bottomCenter,
18+ Alignment .bottomRight
19+ ];
20+ int alignmentIndex = 5 ;
21+
22+ @override
23+ Widget build (BuildContext context) {
24+ return Scaffold (
25+ appBar: AppBar (title: Text ('AppBar' ),),
26+ body: ListView (
27+ children: < Widget > [
28+ SizedBox (
29+ child: Text ('修改alignment的值,non-positined节点会改变位置' ),
30+ ),
31+ Wrap (
32+ alignment: WrapAlignment .spaceBetween,
33+ children: List .generate (9 , (index) {
34+ return FlatButton (
35+ child: Text ('${alignment [index ]}' , style: TextStyle (fontSize: 11.0 ),),
36+ onPressed: (){
37+ setState (() {
38+ alignmentIndex = index;
39+ });
40+ },
41+ );
42+ }),
43+ ),
44+ StackDemo (alignmentValue: alignment[alignmentIndex],)
45+ ],
46+ ),
47+ );
48+ }
49+ }
50+
51+ class StackDemo extends StatelessWidget {
52+ var alignmentValue;
53+ StackDemo ({Key key, @required this .alignmentValue}): super (key: key);
54+
55+ @override
56+ Widget build (BuildContext context) {
57+ return Stack (
58+ textDirection: TextDirection .ltr,
59+ fit: StackFit .loose,
60+ overflow: Overflow .clip,
61+ alignment: alignmentValue,
62+ children: < Widget > [
63+ AspectRatio (
64+ aspectRatio: 16 / 9 ,
65+ child: Image .network (
66+ 'http://pic1.win4000.com/wallpaper/2019-01-31/5c52bf7fdc959_270_185.jpg' ,
67+ fit: BoxFit .cover
68+ ),
69+ ),
70+ Positioned (
71+ top: 32.0 ,
72+ left: 32.0 ,
73+ child: Column (
74+ crossAxisAlignment: CrossAxisAlignment .start,
75+ children: < Widget > [
76+ Text (
77+ '欢聚时代' ,
78+ style: TextStyle (
79+ fontSize: 20.0 ,
80+ color: Colors .red,
81+ fontWeight: FontWeight .bold
82+ ),
83+ ),
84+ Text (
85+ 'Efox Team' ,
86+ style: TextStyle (
87+ fontSize: 14.0 ,
88+ color: Colors .redAccent
89+ ),
90+ )
91+ ],
92+ ),
93+ ),
94+ SizedBox (
95+ child: Icon (Icons .ac_unit, color: Theme .of (context).primaryColor, size: 32.0 ,),
96+ )
97+ ]
98+ );
99+ }
100+ }
0 commit comments