Skip to content

Commit 1027a42

Browse files
author
fbchen
committed
add barrier support
1 parent 2c6a2a0 commit 1027a42

File tree

5 files changed

+553
-244
lines changed

5 files changed

+553
-244
lines changed

README.md

+79-7
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ him.
3333
9. percentage layout
3434
10. guideline
3535
11. constraints and widgets separation
36+
12. barrier
3637

3738
Coming soon:
3839

39-
1. barrier
40-
2. constraints visualization
41-
3. chain
42-
4. dimension ratio
43-
5. more...
40+
1. constraints visualization
41+
2. chain
42+
3. dimension ratio
43+
4. more...
4444

4545
Support platform:
4646

@@ -289,11 +289,15 @@ class ExampleState extends State<Example> {
289289
1. guideline
290290

291291
```dart
292-
class ExampleState extends State<Example> {
293-
ConstraintId guideline = ConstraintId();
292+
import 'package:flutter/material.dart';
293+
import 'package:flutter_constraintlayout/constrait_layout/constraint_layout.dart';
294+
295+
class GuidelineExample extends StatelessWidget {
296+
const GuidelineExample({Key? key}) : super(key: key);
294297
295298
@override
296299
Widget build(BuildContext context) {
300+
ConstraintId guideline = ConstraintId();
297301
return MaterialApp(
298302
home: Scaffold(
299303
body: ConstraintLayout(
@@ -341,6 +345,74 @@ class ExampleState extends State<Example> {
341345

342346
![guideline.webp](https://github.com/hackware1993/flutter-constraintlayout/blob/master/guideline.webp?raw=true)
343347

348+
2. barrier
349+
350+
```dart
351+
import 'package:flutter/material.dart';
352+
import 'package:flutter_constraintlayout/constrait_layout/constraint_layout.dart';
353+
354+
class BarrierExample extends StatelessWidget {
355+
const BarrierExample({Key? key}) : super(key: key);
356+
357+
@override
358+
Widget build(BuildContext context) {
359+
ConstraintId leftChild = ConstraintId();
360+
ConstraintId rightChild = ConstraintId();
361+
ConstraintId barrier = ConstraintId();
362+
return MaterialApp(
363+
home: Scaffold(
364+
body: ConstraintLayout(
365+
debugShowGuideline: true,
366+
children: [
367+
Container(
368+
color: const Color(0xFF005BBB),
369+
).applyConstraint(
370+
id: leftChild,
371+
width: 200,
372+
height: 200,
373+
top: parent.top,
374+
left: parent.left,
375+
),
376+
Container(
377+
color: const Color(0xFFFFD500),
378+
).applyConstraint(
379+
id: rightChild,
380+
width: 200,
381+
height: matchConstraint,
382+
right: parent.right,
383+
top: parent.top,
384+
bottom: parent.bottom,
385+
heightPercent: 0.5,
386+
verticalBias: 0,
387+
),
388+
Barrier(
389+
id: barrier,
390+
direction: BarrierDirection.bottom,
391+
referencedIds: [leftChild, rightChild],
392+
),
393+
const Text(
394+
'Align to barrier',
395+
style: TextStyle(
396+
fontSize: 40,
397+
color: Colors.blue,
398+
),
399+
).applyConstraint(
400+
width: wrapContent,
401+
height: wrapContent,
402+
centerHorizontalTo: parent,
403+
top: barrier.bottom,
404+
goneMargin: const EdgeInsets.only(top: 20),
405+
)
406+
],
407+
),
408+
),
409+
);
410+
}
411+
}
412+
```
413+
414+
![barrier.gif](https://github.com/hackware1993/flutter-constraintlayout/blob/master/barrier.gif?raw=true)
415+
344416
# Support me
345417

346418
If it helps you a lot, consider sponsoring me a cup of milk tea.

barrier.gif

57.4 KB
Loading

0 commit comments

Comments
 (0)