Skip to content

Commit e5eb7a1

Browse files
author
fbchen
committed
update example
1 parent d1cdcff commit e5eb7a1

File tree

2 files changed

+62
-31
lines changed

2 files changed

+62
-31
lines changed

example/home.dart

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,37 @@ class ExampleHome extends StatelessWidget {
5353
).applyConstraint(
5454
topCenterTo: parent,
5555
),
56-
...constraintGrid(
57-
id: ConstraintId('exampleList'),
58-
margin: const EdgeInsets.only(
59-
top: 20,
56+
SingleChildScrollView(
57+
child: Column(
58+
children: [
59+
for (int i = 0; i < keyList.length; i++)
60+
SizedBox(
61+
width: double.infinity,
62+
height: 40,
63+
child: TextButton(
64+
onPressed: exampleMap[keyList[i]] == null
65+
? null
66+
: () {
67+
Navigator.of(context)
68+
.push(MaterialPageRoute(builder: (_) {
69+
return exampleMap[keyList[i]]!;
70+
}));
71+
},
72+
child: Text(
73+
keyList[i],
74+
style: const TextStyle(
75+
fontSize: 20,
76+
),
77+
),
78+
),
79+
)
80+
],
6081
),
61-
left: parent.left,
62-
top: rId(0).bottom,
63-
itemCount: keyList.length,
64-
columnCount: 1,
65-
itemWidth: matchParent,
66-
itemHeight: 40,
67-
itemBuilder: (index) {
68-
Widget? example = exampleMap[keyList[index]];
69-
return TextButton(
70-
onPressed: example == null
71-
? null
72-
: () {
73-
Navigator.of(context)
74-
.push(MaterialPageRoute(builder: (_) {
75-
return example;
76-
}));
77-
},
78-
child: Text(
79-
keyList[index],
80-
style: const TextStyle(
81-
fontSize: 20,
82-
),
83-
),
84-
);
85-
},
82+
).applyConstraint(
83+
width: matchParent,
84+
height: matchConstraint,
85+
top: sId(-1).bottom,
86+
bottom: sId(1).top,
8687
),
8788
const Text(
8889
'Powered by Flutter Web & ConstraintLayout',
@@ -91,7 +92,6 @@ class ExampleHome extends StatelessWidget {
9192
fontWeight: FontWeight.bold,
9293
height: 1.5,
9394
),
94-
textAlign: TextAlign.center,
9595
).applyConstraint(
9696
bottomCenterTo: parent,
9797
margin: const EdgeInsets.only(

example/wrapper_constraints.dart

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ import 'package:flutter_constraintlayout/src/constraint_layout.dart';
33

44
import 'custom_app_bar.dart';
55

6-
class WrapperConstraintsExample extends StatelessWidget {
6+
class WrapperConstraintsExample extends StatefulWidget {
77
const WrapperConstraintsExample({Key? key}) : super(key: key);
88

9+
@override
10+
State createState() => WrapperConstraintsExampleState();
11+
}
12+
13+
class WrapperConstraintsExampleState extends State<WrapperConstraintsExample> {
14+
double leftX = 0;
15+
double rightX = 0;
16+
917
Widget item(String text, [Color color = Colors.redAccent]) {
1018
return Container(
1119
width: 100,
@@ -55,6 +63,9 @@ class WrapperConstraintsExample extends StatelessWidget {
5563
),
5664
item('centerTopRightTo').applyConstraint(
5765
centerTopRightTo: rId(0),
66+
callback: (_, rect) {
67+
leftX = rect.right;
68+
},
5869
),
5970
item('centerCenterLeftTo').applyConstraint(
6071
centerCenterLeftTo: rId(0),
@@ -83,6 +94,12 @@ class WrapperConstraintsExample extends StatelessWidget {
8394
),
8495
item('outTopLeftTo').applyConstraint(
8596
outTopLeftTo: rId(1),
97+
callback: (_, rect) {
98+
rightX = rect.left;
99+
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
100+
setState(() {});
101+
});
102+
},
86103
),
87104
item('outTopCenterTo').applyConstraint(
88105
outTopCenterTo: rId(1),
@@ -132,6 +149,20 @@ class WrapperConstraintsExample extends StatelessWidget {
132149
item('bottomRightTo', Colors.green).applyConstraint(
133150
bottomRightTo: rId(1),
134151
),
152+
const Text(
153+
'The display area is overlapping\nPlease view it in full screen on the computer',
154+
style: TextStyle(
155+
color: Colors.redAccent,
156+
fontSize: 16,
157+
),
158+
textAlign: TextAlign.center,
159+
).applyConstraint(
160+
topCenterTo: parent,
161+
margin: const EdgeInsets.only(
162+
top: 5,
163+
),
164+
visibility: rightX - 1 < leftX ? visible : gone,
165+
),
135166
],
136167
),
137168
);

0 commit comments

Comments
 (0)