"Fossies" - the Fresh Open Source Software Archive 
Member "flutter-3.7.1/packages/flutter/test/widgets/align_test.dart" (1 Feb 2023, 4354 Bytes) of package /linux/misc/flutter-3.7.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 // Copyright 2014 The Flutter 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
5 import 'package:flutter/widgets.dart';
6 import 'package:flutter_test/flutter_test.dart';
7
8 void main() {
9 testWidgets('Align smoke test', (WidgetTester tester) async {
10 await tester.pumpWidget(
11 Align(
12 alignment: const Alignment(0.50, 0.50),
13 child: Container(),
14 ),
15 );
16
17 await tester.pumpWidget(
18 Align(
19 child: Container(),
20 ),
21 );
22
23 await tester.pumpWidget(
24 const Align(
25 alignment: Alignment.topLeft,
26 ),
27 );
28 await tester.pumpWidget(const Directionality(
29 textDirection: TextDirection.rtl,
30 child: Align(
31 alignment: AlignmentDirectional.topStart,
32 ),
33 ));
34 await tester.pumpWidget(
35 const Align(
36 alignment: Alignment.topLeft,
37 ),
38 );
39 });
40
41 testWidgets('Align control test (LTR)', (WidgetTester tester) async {
42 await tester.pumpWidget(const Directionality(
43 textDirection: TextDirection.ltr,
44 child: Align(
45 alignment: AlignmentDirectional.topStart,
46 child: SizedBox(width: 100.0, height: 80.0),
47 ),
48 ));
49
50 expect(tester.getTopLeft(find.byType(SizedBox)).dx, 0.0);
51 expect(tester.getBottomRight(find.byType(SizedBox)).dx, 100.0);
52
53 await tester.pumpWidget(const Directionality(
54 textDirection: TextDirection.ltr,
55 child: Align(
56 alignment: Alignment.topLeft,
57 child: SizedBox(width: 100.0, height: 80.0),
58 ),
59 ));
60
61 expect(tester.getTopLeft(find.byType(SizedBox)).dx, 0.0);
62 expect(tester.getBottomRight(find.byType(SizedBox)).dx, 100.0);
63 });
64
65 testWidgets('Align control test (RTL)', (WidgetTester tester) async {
66 await tester.pumpWidget(const Directionality(
67 textDirection: TextDirection.rtl,
68 child: Align(
69 alignment: AlignmentDirectional.topStart,
70 child: SizedBox(width: 100.0, height: 80.0),
71 ),
72 ));
73
74 expect(tester.getTopLeft(find.byType(SizedBox)).dx, 700.0);
75 expect(tester.getBottomRight(find.byType(SizedBox)).dx, 800.0);
76
77 await tester.pumpWidget(const Directionality(
78 textDirection: TextDirection.ltr,
79 child: Align(
80 alignment: Alignment.topLeft,
81 child: SizedBox(width: 100.0, height: 80.0),
82 ),
83 ));
84
85 expect(tester.getTopLeft(find.byType(SizedBox)).dx, 0.0);
86 expect(tester.getBottomRight(find.byType(SizedBox)).dx, 100.0);
87 });
88
89 testWidgets('Shrink wraps in finite space', (WidgetTester tester) async {
90 final GlobalKey alignKey = GlobalKey();
91 await tester.pumpWidget(
92 SingleChildScrollView(
93 child: Align(
94 key: alignKey,
95 child: const SizedBox(
96 width: 10.0,
97 height: 10.0,
98 ),
99 ),
100 ),
101 );
102
103 final Size size = alignKey.currentContext!.size!;
104 expect(size.width, equals(800.0));
105 expect(size.height, equals(10.0));
106 });
107
108 testWidgets('Align widthFactor', (WidgetTester tester) async {
109 await tester.pumpWidget(
110 Directionality(
111 textDirection: TextDirection.ltr,
112 child: Row(
113 crossAxisAlignment: CrossAxisAlignment.start,
114 mainAxisAlignment: MainAxisAlignment.center,
115 children: const <Widget>[
116 Align(
117 widthFactor: 0.5,
118 child: SizedBox(
119 height: 100.0,
120 width: 100.0,
121 ),
122 ),
123 ],
124 ),
125 ),
126 );
127 final RenderBox box = tester.renderObject<RenderBox>(find.byType(Align));
128 expect(box.size.width, equals(50.0));
129 });
130
131 testWidgets('Align heightFactor', (WidgetTester tester) async {
132 await tester.pumpWidget(
133 Directionality(
134 textDirection: TextDirection.ltr,
135 child: Column(
136 mainAxisAlignment: MainAxisAlignment.center,
137 crossAxisAlignment: CrossAxisAlignment.start,
138 children: const <Widget>[
139 Align(
140 heightFactor: 0.5,
141 child: SizedBox(
142 height: 100.0,
143 width: 100.0,
144 ),
145 ),
146 ],
147 ),
148 ),
149 );
150 final RenderBox box = tester.renderObject<RenderBox>(find.byType(Align));
151 expect(box.size.height, equals(50.0));
152 });
153 }