Skip to content

Commit d2f89ee

Browse files
author
fbchen
committed
add arbitrary position support
1 parent 553396e commit d2f89ee

File tree

5 files changed

+602
-499
lines changed

5 files changed

+602
-499
lines changed

example/arbitrary_position.dart

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import 'dart:math';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_constraintlayout/src/constraint_layout.dart';
5+
6+
import 'custom_app_bar.dart';
7+
8+
class ArbitraryPositionExample extends StatefulWidget {
9+
const ArbitraryPositionExample({Key? key}) : super(key: key);
10+
11+
@override
12+
State createState() => ArbitraryPositionExampleState();
13+
}
14+
15+
class ArbitraryPositionExampleState extends State<ArbitraryPositionExample> {
16+
@override
17+
Widget build(BuildContext context) {
18+
return Scaffold(
19+
appBar: const CustomAppBar(
20+
title: 'Arbitrary Position',
21+
codePath: 'example/arbitrary_position.dart',
22+
),
23+
body: ConstraintLayout(
24+
debugPrintLayoutTime: true,
25+
children: [
26+
Container(
27+
color: Colors.black,
28+
child: const Text(
29+
'Arbitrary position gives you more freedom\nadjust the window size to see the effect',
30+
style: TextStyle(
31+
color: Colors.white,
32+
fontSize: 16,
33+
),
34+
textAlign: TextAlign.center,
35+
),
36+
).applyConstraint(
37+
width: matchParent,
38+
height: 50,
39+
top: parent.top,
40+
),
41+
Container(
42+
color: Colors.orange,
43+
).applyConstraint(
44+
size: matchConstraint,
45+
anchors: [sId(-1)],
46+
calcSizeCallback: (parent, anchors) {
47+
return const BoxConstraints.tightFor(
48+
width: 100,
49+
height: 100,
50+
);
51+
},
52+
calcOffsetCallback: (parent, self, anchors) {
53+
return Offset(
54+
min(
55+
max(
56+
300,
57+
anchors[0].getRight() -
58+
anchors[0].getMeasuredWidth() / 2),
59+
700),
60+
max(400, parent.size.height - self.getMeasuredHeight()));
61+
},
62+
)
63+
],
64+
),
65+
);
66+
}
67+
}

example/home.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
33

4+
import 'arbitrary_position.dart';
45
import 'badge.dart';
56
import 'barrier.dart';
67
import 'charts.dart';
@@ -40,6 +41,7 @@ class ExampleHome extends StatelessWidget {
4041
'Staggered Grid': const StaggeredGridExample(),
4142
'Circle Position': const CirclePositionExample(),
4243
'Pinned Position': const PinnedPositionExample(),
44+
'Arbitrary Position': const ArbitraryPositionExample(),
4345
'Self wrapContent': const SelfWrapContentExample(),
4446
'Margin': const MarginExample(),
4547
'Charts': const ChartsExample(),

0 commit comments

Comments
 (0)