Skip to content

Commit bafb45d

Browse files
committed
update example
1 parent d2eeb48 commit bafb45d

File tree

10 files changed

+118
-39
lines changed

10 files changed

+118
-39
lines changed

example/badge.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class BadgeExample extends StatelessWidget {
1212
return Scaffold(
1313
appBar: const CustomAppBar(
1414
title: 'Badge',
15+
codePath: 'example/badge.dart',
1516
),
1617
body: ConstraintLayout(
1718
children: [
@@ -33,8 +34,6 @@ class BadgeExample extends StatelessWidget {
3334
),
3435
),
3536
).applyConstraint(
36-
width: wrapContent,
37-
height: wrapContent,
3837
left: anchor.right,
3938
bottom: anchor.top,
4039
translate: const Offset(-0.5, 0.5),

example/barrier.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,25 @@ class BarrierExample extends StatelessWidget {
1414
return Scaffold(
1515
appBar: const CustomAppBar(
1616
title: 'Barrier',
17+
codePath: 'example/barrier.dart',
1718
),
1819
body: ConstraintLayout(
19-
debugShowGuideline: true,
2020
children: [
2121
Container(
2222
color: const Color(0xFF005BBB),
2323
).applyConstraint(
2424
id: leftChild,
2525
width: 200,
2626
height: 200,
27-
top: parent.top,
28-
left: parent.left,
27+
topLeftTo: parent,
2928
),
3029
Container(
3130
color: const Color(0xFFFFD500),
3231
).applyConstraint(
3332
id: rightChild,
3433
width: 200,
3534
height: matchConstraint,
36-
right: parent.right,
37-
top: parent.top,
38-
bottom: parent.bottom,
35+
centerRightTo: parent,
3936
heightPercent: 0.5,
4037
verticalBias: 0,
4138
),
@@ -51,11 +48,8 @@ class BarrierExample extends StatelessWidget {
5148
color: Colors.blue,
5249
),
5350
).applyConstraint(
54-
width: wrapContent,
55-
height: wrapContent,
5651
centerHorizontalTo: parent,
5752
top: barrier.bottom,
58-
goneMargin: const EdgeInsets.only(top: 20),
5953
)
6054
],
6155
),

example/code.dart

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter/services.dart';
3+
import 'package:flutter_constraintlayout/src/constraint_layout.dart';
4+
5+
import 'custom_app_bar.dart';
6+
7+
class CodeViewWidget extends StatefulWidget {
8+
final String codePath;
9+
10+
const CodeViewWidget({
11+
Key? key,
12+
required this.codePath,
13+
}) : super(key: key);
14+
15+
@override
16+
State createState() => CodeViewState();
17+
}
18+
19+
class CodeViewState extends State<CodeViewWidget> {
20+
String? code;
21+
22+
@override
23+
void initState() {
24+
super.initState();
25+
loadCode();
26+
}
27+
28+
void loadCode() async {
29+
code = await rootBundle.loadString(widget.codePath);
30+
setState(() {});
31+
}
32+
33+
@override
34+
Widget build(BuildContext context) {
35+
return Scaffold(
36+
appBar: const CustomAppBar(),
37+
body: ConstraintLayout(
38+
children: [
39+
SingleChildScrollView(
40+
child: Padding(
41+
child: Text(
42+
code ?? '',
43+
style: const TextStyle(
44+
color: Colors.black,
45+
fontSize: 16,
46+
),
47+
),
48+
padding: const EdgeInsets.only(
49+
left: 20,
50+
top: 20,
51+
),
52+
),
53+
).applyConstraint(
54+
width: matchParent,
55+
height: matchParent,
56+
)
57+
],
58+
),
59+
);
60+
}
61+
}

example/complex_list.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ComplexListExample extends StatelessWidget {
2626
return Scaffold(
2727
appBar: const CustomAppBar(
2828
title: 'ComplexList',
29+
codePath: 'example/complex_list.dart',
2930
),
3031
body: ListView.builder(
3132
itemBuilder: (context, index) {
@@ -54,15 +55,13 @@ class ComplexListExample extends StatelessWidget {
5455
fit: BoxFit.fill,
5556
).applyConstraint(
5657
width: 100,
57-
height: wrapContent,
5858
centerLeftTo: parent,
5959
),
6060
Image.asset(
6161
'assets/test2.webp',
6262
fit: BoxFit.fill,
6363
).applyConstraint(
6464
width: 150,
65-
height: wrapContent,
6665
centerRightTo: parent,
6766
),
6867
Text(

example/custom_app_bar.dart

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

4+
import 'code.dart';
5+
46
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
57
final double? height;
68
final Color backgroundColor;
79
final String title;
8-
final String leftImg;
9-
final GestureTapCallback? onLeftTap;
10-
final GestureTapCallback? onRightTap;
11-
final String? rightButtonText;
12-
13-
static const double DEFAULT_HEIGHT = 64;
10+
final String? codePath;
1411

1512
const CustomAppBar({
1613
Key? key,
1714
this.height,
1815
this.backgroundColor = Colors.white,
1916
this.title = '',
20-
this.leftImg = 'assets/icon_back.webp',
21-
this.onLeftTap,
22-
this.rightButtonText,
23-
this.onRightTap,
17+
this.codePath,
2418
}) : super(key: key);
2519

2620
@override
2721
Size get preferredSize {
28-
return Size(double.infinity, height ?? DEFAULT_HEIGHT);
22+
return Size(double.infinity, height ?? 64);
23+
}
24+
25+
void push(BuildContext context, Widget widget) {
26+
Navigator.of(context).push(MaterialPageRoute(builder: (_) {
27+
return widget;
28+
}));
2929
}
3030

3131
@override
3232
Widget build(BuildContext context) {
3333
return Container(
34-
height: height ?? DEFAULT_HEIGHT,
34+
height: height ?? 64,
3535
color: backgroundColor,
3636
margin: EdgeInsets.only(
3737
top: MediaQuery.of(context).viewPadding.top,
@@ -40,7 +40,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
4040
children: [
4141
GestureDetector(
4242
child: Image.asset(
43-
leftImg,
43+
'assets/icon_back.webp',
4444
fit: BoxFit.fill,
4545
),
4646
onTap: () {
@@ -65,7 +65,32 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
6565
),
6666
).applyConstraint(
6767
centerTo: parent,
68-
)
68+
),
69+
if (codePath != null)
70+
GestureDetector(
71+
child: const Text(
72+
'View Code',
73+
style: TextStyle(
74+
fontSize: 18,
75+
color: Colors.blue,
76+
fontWeight: FontWeight.bold,
77+
),
78+
),
79+
onTap: () {
80+
push(
81+
context,
82+
CodeViewWidget(
83+
codePath: codePath!,
84+
),
85+
);
86+
},
87+
).applyConstraint(
88+
centerRightTo: parent,
89+
margin: const EdgeInsets.only(
90+
right: 20,
91+
),
92+
clickPadding: const EdgeInsets.all(20),
93+
)
6994
],
7095
),
7196
);

example/guideline.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class GuidelineExample extends StatelessWidget {
1212
return Scaffold(
1313
appBar: const CustomAppBar(
1414
title: 'Guideline',
15+
codePath: 'example/guideline.dart',
1516
),
1617
body: ConstraintLayout(
1718
children: [
@@ -42,9 +43,8 @@ class GuidelineExample extends StatelessWidget {
4243
fontSize: 40,
4344
color: Colors.white,
4445
),
46+
textAlign: TextAlign.center,
4547
).applyConstraint(
46-
width: wrapContent,
47-
height: wrapContent,
4848
centerHorizontalTo: parent,
4949
bottom: guideline.bottom,
5050
)

example/home.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'barrier.dart';
55
import 'complex_list.dart';
66
import 'guideline.dart';
77
import 'preprocess_complex_list.dart';
8-
import 'sumary.dart';
8+
import 'summary.dart';
99

1010
class ExampleHome extends StatelessWidget {
1111
const ExampleHome({Key? key}) : super(key: key);
@@ -63,7 +63,7 @@ class ExampleHome extends StatelessWidget {
6363
}
6464

6565
void push(BuildContext context, Widget widget) {
66-
Navigator.of(context).push(MaterialPageRoute(builder: (context2) {
66+
Navigator.of(context).push(MaterialPageRoute(builder: (_) {
6767
return widget;
6868
}));
6969
}

example/preprocess_complex_list.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ class PreprocessComplexListExample extends StatelessWidget {
4242
),
4343
Constraint(
4444
width: 100,
45-
height: wrapContent,
4645
centerLeftTo: parent,
4746
id: leftImg,
4847
),
4948
Constraint(
5049
width: 150,
51-
height: wrapContent,
5250
centerRightTo: parent,
5351
id: rightImg,
5452
),
@@ -96,6 +94,7 @@ class PreprocessComplexListExample extends StatelessWidget {
9694
return Scaffold(
9795
appBar: const CustomAppBar(
9896
title: 'PreprocessComplexList',
97+
codePath: 'example/preprocess_complex_list.dart',
9998
),
10099
body: ListView.builder(
101100
itemBuilder: (context, index) {

example/sumary.dart renamed to example/summary.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class SummaryExampleState extends State<SummaryExample> {
3333
return Scaffold(
3434
appBar: const CustomAppBar(
3535
title: 'Summary',
36+
codePath: 'example/summary.dart',
3637
),
3738
backgroundColor: Colors.black,
3839
body: ConstraintLayout(
39-
debugShowGuideline: true,
4040
// Constraints can be separated from widgets
4141
childConstraints: [
4242
Constraint(
@@ -89,8 +89,6 @@ class SummaryExampleState extends State<SummaryExample> {
8989
child: const Text('box3'),
9090
).applyConstraint(
9191
id: box3,
92-
width: wrapContent,
93-
height: wrapContent,
9492
right: box1.left,
9593
top: box1.bottom,
9694
),
@@ -168,8 +166,6 @@ class SummaryExampleState extends State<SummaryExample> {
168166
),
169167
).applyConstraint(
170168
id: box9,
171-
width: wrapContent,
172-
height: wrapContent,
173169
baseline: box7.baseline,
174170
left: box7.left,
175171
),

pubspec.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ flutter:
2121
assets:
2222
- assets/test.webp
2323
- assets/test2.webp
24-
- assets/icon_back.webp
24+
- assets/icon_back.webp
25+
- example/badge.dart
26+
- example/barrier.dart
27+
- example/complex_list.dart
28+
- example/guideline.dart
29+
- example/preprocess_complex_list.dart
30+
- example/summary.dart

0 commit comments

Comments
 (0)