|
| 1 | +// Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
1 | 5 | import 'package:flutter/material.dart';
|
2 | 6 |
|
3 | 7 | void main() => runApp(MyApp());
|
4 | 8 |
|
5 | 9 | class MyApp extends StatelessWidget {
|
6 |
| - // This widget is the root of your application. |
7 | 10 | @override
|
8 | 11 | Widget build(BuildContext context) {
|
9 | 12 | return MaterialApp(
|
10 | 13 | title: 'Flutter Align Demo',
|
11 |
| - home: Scaffold(body: AlignExamples()), |
| 14 | + home: Scaffold( |
| 15 | + body: AlignExamples(), |
| 16 | + ), |
12 | 17 | );
|
13 | 18 | }
|
14 | 19 | }
|
15 | 20 |
|
16 | 21 | class AlignExamples extends StatelessWidget {
|
17 | 22 | @override
|
18 | 23 | Widget build(BuildContext context) {
|
19 |
| - return Column(children: <Widget>[ |
20 |
| - Flexible( |
21 |
| - flex: 1, |
22 |
| - child: Align( |
23 |
| - alignment: Alignment(0, 0), |
24 |
| - child: Text('Centered!'), |
25 |
| - ), |
26 |
| - ), |
27 |
| - Flexible( |
28 |
| - flex: 1, |
29 |
| - child: Stack(children: <Widget>[ |
30 |
| - Align( |
31 |
| - alignment: Alignment(-1, -1), |
32 |
| - child: Text('Top Left!'), |
33 |
| - ), |
34 |
| - Align( |
35 |
| - alignment: Alignment(0, 0), |
36 |
| - child: Text('Centered!'), |
37 |
| - ), |
38 |
| - Align( |
39 |
| - alignment: Alignment(1, 1), |
40 |
| - child: Text('Bottom Right!'), |
41 |
| - ), |
42 |
| - Align( |
43 |
| - alignment: Alignment.topCenter, |
44 |
| - child: Text('TopCenter!'), |
| 24 | + return Column( |
| 25 | + children: [ |
| 26 | + Flexible( |
| 27 | + flex: 1, |
| 28 | + child: Container( |
| 29 | + color: Colors.black26, |
| 30 | + child: Align( |
| 31 | + alignment: Alignment(0, 0), |
| 32 | + child: Text('Centered!'), |
| 33 | + ), |
45 | 34 | ),
|
46 |
| - Align( |
47 |
| - alignment: Alignment.bottomCenter, |
48 |
| - child: Text('TopCenter!'), |
| 35 | + ), |
| 36 | + Flexible( |
| 37 | + flex: 1, |
| 38 | + child: Stack( |
| 39 | + children: <Widget>[ |
| 40 | + Positioned.fill( |
| 41 | + child: Container( |
| 42 | + color: Colors.black12, |
| 43 | + ), |
| 44 | + ), |
| 45 | + Align( |
| 46 | + alignment: Alignment(-1, -1), |
| 47 | + child: Text('Top Left!'), |
| 48 | + ), |
| 49 | + Align( |
| 50 | + alignment: Alignment(0, 0), |
| 51 | + child: Text('Centered!'), |
| 52 | + ), |
| 53 | + Align( |
| 54 | + alignment: Alignment(1, 1), |
| 55 | + child: Text('Bottom Right!'), |
| 56 | + ), |
| 57 | + Align( |
| 58 | + alignment: Alignment.topCenter, |
| 59 | + child: Text('TopCenter!'), |
| 60 | + ), |
| 61 | + Align( |
| 62 | + alignment: Alignment.bottomCenter, |
| 63 | + child: Text('TopCenter!'), |
| 64 | + ), |
| 65 | + ], |
49 | 66 | ),
|
50 |
| - ]), |
51 |
| - ), |
52 |
| - Flexible( |
53 |
| - flex: 1, |
54 |
| - child: Container( |
55 |
| - child: Align( |
56 |
| - alignment: Alignment(-.5, -.5), |
57 |
| - child: Text('25% in'), |
58 |
| - )), |
59 |
| - ), |
60 |
| - Flexible( |
61 |
| - flex: 1, |
62 |
| - child: Container( |
63 |
| - child: Align( |
64 |
| - alignment: Alignment(.5, .5), |
65 |
| - child: Text('75% in'), |
66 |
| - )), |
67 |
| - ), |
68 |
| - ]); |
| 67 | + ), |
| 68 | + Flexible( |
| 69 | + flex: 1, |
| 70 | + child: Container( |
| 71 | + color: Colors.black26, |
| 72 | + child: Align( |
| 73 | + alignment: Alignment(-.5, -.5), |
| 74 | + child: Text('25% in'), |
| 75 | + )), |
| 76 | + ), |
| 77 | + Flexible( |
| 78 | + flex: 1, |
| 79 | + child: Container( |
| 80 | + color: Colors.black12, |
| 81 | + child: Align( |
| 82 | + alignment: Alignment(.5, .5), |
| 83 | + child: Text('75% in'), |
| 84 | + )), |
| 85 | + ), |
| 86 | + ], |
| 87 | + ); |
69 | 88 | }
|
70 | 89 | }
|
0 commit comments