@@ -129,21 +129,11 @@ dependencies:
129
129
import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
130
130
```
131
131
132
- # Example
132
+ # Example [ Flutter Web Online Example ] ( https://constraintlayout.flutterfirst.cn )
133
133
134
- View [ Flutter Web Online Example ] ( https://constraintlayout.flutterfirst.cn )
134
+ ![ effect.gif ] ( https://github.com/hackware1993/flutter- constraintlayout/blob/master/effect.gif?raw=true )
135
135
136
136
``` dart
137
- import 'package:flutter/material.dart';
138
- import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
139
-
140
- class Example extends StatefulWidget {
141
- const Example({Key? key}) : super(key: key);
142
-
143
- @override
144
- State createState() => ExampleState();
145
- }
146
-
147
137
class ExampleState extends State<Example> {
148
138
double x = 0;
149
139
double y = 0;
@@ -350,16 +340,13 @@ class ExampleState extends State<Example> {
350
340
}
351
341
```
352
342
353
- ![ example.webp] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/effect.gif?raw=true )
354
-
355
343
# Advanced usage
356
344
357
345
1 . guideline [ Flutter Web Online Example] ( https://constraintlayout.flutterfirst.cn )
358
346
359
- ``` dart
360
- import 'package:flutter/material.dart';
361
- import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
347
+ ![ guideline.webp] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/guideline.webp?raw=true )
362
348
349
+ ``` dart
363
350
class GuidelineExample extends StatelessWidget {
364
351
const GuidelineExample({Key? key}) : super(key: key);
365
352
@@ -411,14 +398,11 @@ class GuidelineExample extends StatelessWidget {
411
398
}
412
399
```
413
400
414
- ![ guideline.webp] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/guideline.webp?raw=true )
415
-
416
401
2 . barrier [ Flutter Web Online Example] ( https://constraintlayout.flutterfirst.cn )
417
402
418
- ``` dart
419
- import 'package:flutter/material.dart';
420
- import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
403
+ ![ barrier.gif] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/barrier.gif?raw=true )
421
404
405
+ ``` dart
422
406
class BarrierExample extends StatelessWidget {
423
407
const BarrierExample({Key? key}) : super(key: key);
424
408
@@ -479,61 +463,64 @@ class BarrierExample extends StatelessWidget {
479
463
}
480
464
```
481
465
482
- ![ barrier.gif] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/barrier.gif?raw=true )
483
-
484
466
3 . badge [ Flutter Web Online Example] ( https://constraintlayout.flutterfirst.cn )
485
467
486
- ``` dart
487
- import 'package:flutter/material.dart';
488
- import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
468
+ ![ badge.webp] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/badge.webp?raw=true )
489
469
470
+ ``` dart
490
471
class BadgeExample extends StatelessWidget {
491
472
const BadgeExample({Key? key}) : super(key: key);
492
473
493
474
@override
494
475
Widget build(BuildContext context) {
495
476
ConstraintId anchor = ConstraintId('anchor');
496
- return MaterialApp(
497
- home: Scaffold(
498
- body: ConstraintLayout(
499
- children: [
500
- Container(
501
- color: Colors.yellow,
502
- ).applyConstraint(
503
- width: 200,
504
- height: 200,
505
- centerTo: parent,
506
- id: anchor,
507
- ),
508
- Container(
509
- color: Colors.green,
510
- child: const Text(
511
- 'Indeterminate badge size',
512
- style: TextStyle(
513
- color: Colors.black,
514
- fontSize: 20,
515
- ),
477
+ return Scaffold(
478
+ body: ConstraintLayout(
479
+ children: [
480
+ Container(
481
+ color: Colors.yellow,
482
+ ).applyConstraint(
483
+ width: 200,
484
+ height: 200,
485
+ centerTo: parent,
486
+ id: anchor,
487
+ ),
488
+ Container(
489
+ color: Colors.green,
490
+ child: const Text(
491
+ 'Indeterminate badge size',
492
+ style: TextStyle(
493
+ color: Colors.black,
494
+ fontSize: 20,
516
495
),
517
- ).applyConstraint(
518
- width: wrapContent,
519
- height: wrapContent,
520
- left: anchor.right,
521
- bottom: anchor.top,
522
- translate: const Offset(-0.5, 0.5),
523
- percentageTranslate: true,
524
- )
525
- ],
526
- ),
496
+ ),
497
+ ).applyConstraint(
498
+ left: anchor.right,
499
+ bottom: anchor.top,
500
+ translate: const Offset(-0.5, 0.5),
501
+ percentageTranslate: true,
502
+ ),
503
+ Container(
504
+ color: Colors.green,
505
+ ).applyConstraint(
506
+ width: 100,
507
+ height: 100,
508
+ left: anchor.right,
509
+ right: anchor.right,
510
+ top: anchor.bottom,
511
+ bottom: anchor.bottom,
512
+ )
513
+ ],
527
514
),
528
515
);
529
516
}
530
517
}
531
518
```
532
519
533
- ![ badge.webp] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/badge.webp?raw=true )
534
-
535
520
4 . grid [ Flutter Web Online Example] ( https://constraintlayout.flutterfirst.cn )
536
521
522
+ ![ grid.webp] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/grid.webp?raw=true )
523
+
537
524
``` dart
538
525
class GridExample extends StatelessWidget {
539
526
const GridExample({Key? key}) : super(key: key);
@@ -578,10 +565,10 @@ class GridExample extends StatelessWidget {
578
565
}
579
566
```
580
567
581
- ![ grid.webp] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/grid.webp?raw=true )
582
-
583
568
5 . staggered grid [ Flutter Web Online Example] ( https://constraintlayout.flutterfirst.cn )
584
569
570
+ ![ staggered_grid.gif] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/staggered_grid.gif?raw=true )
571
+
585
572
``` dart
586
573
class StaggeredGridExample extends StatelessWidget {
587
574
const StaggeredGridExample({Key? key}) : super(key: key);
@@ -685,10 +672,10 @@ class StaggeredGridExample extends StatelessWidget {
685
672
}
686
673
```
687
674
688
- ![ staggered_grid.gif] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/staggered_grid.gif?raw=true )
689
-
690
675
6 . circle position [ Flutter Web Online Example] ( https://constraintlayout.flutterfirst.cn )
691
676
677
+ ![ circle_position.gif] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/circle_position.gif?raw=true )
678
+
692
679
``` dart
693
680
class CirclePositionExampleState extends State<CirclePositionExample> {
694
681
late Timer timer;
@@ -842,17 +829,12 @@ class CirclePositionExampleState extends State<CirclePositionExample> {
842
829
}
843
830
```
844
831
845
- ![ circle_position.gif] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/circle_position.gif?raw=true )
846
-
847
832
# Performance optimization
848
833
849
834
1 . When the layout is complex, if the child elements need to be repainted frequently, it is
850
835
recommended to use RepaintBoundary to improve performance.
851
836
852
837
``` dart
853
- import 'package:flutter/material.dart';
854
- import 'package:flutter_constraintlayout/src/constraint_layout.dart';
855
-
856
838
class OffPaintExample extends StatelessWidget {
857
839
const OffPaintExample({Key? key}) : super(key: key);
858
840
@@ -881,9 +863,6 @@ class OffPaintExample extends StatelessWidget {
881
863
can use OffBuildWidget to avoid the rebuilding of the child element.
882
864
883
865
``` dart
884
- import 'package:flutter/material.dart';
885
- import 'package:flutter_constraintlayout/src/constraint_layout.dart';
886
-
887
866
class OffBuildExample extends StatelessWidget {
888
867
const OffBuildExample({Key? key}) : super(key: key);
889
868
0 commit comments