Skip to content

Commit 5076d60

Browse files
committed
布局
1 parent 08daef7 commit 5076d60

File tree

3 files changed

+86
-18
lines changed

3 files changed

+86
-18
lines changed

example/lib/main.dart

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ showAlertDialog(BuildContext context) {
4747
makeTextButton("body", () {
4848
YYAlertDialogBody(context);
4949
}),
50-
makeTextButton("head&body", () {
50+
makeTextButton("head", () {
5151
YYAlertDialogHeadAndBody(context);
5252
}),
53+
makeTextButton("divider", () {
54+
YYAlertDialogWithDivider(context);
55+
}),
5356
],
5457
),
5558
Text("2、dialog gravity"),
@@ -81,15 +84,39 @@ showAlertDialog(BuildContext context) {
8184
gravity: Gravity.right,
8285
);
8386
}),
87+
makeTextButton("center", () {
88+
YYAlertDialogWithGravity(
89+
context: context,
90+
width: 250.0,
91+
gravity: Gravity.center,
92+
);
93+
}),
8494
],
8595
),
8696
Text("3、double button gravity"),
8797
Row(
8898
children: <Widget>[
89-
makeTextButton("bottom", () {}),
90-
makeTextButton("top", () {}),
91-
makeTextButton("left", () {}),
92-
makeTextButton("right", () {}),
99+
makeTextButton("left", () {
100+
YYAlertDialogWithGravity(
101+
context: context,
102+
width: 250.0,
103+
doubleButtonGravity: Gravity.left,
104+
);
105+
}),
106+
makeTextButton("right", () {
107+
YYAlertDialogWithGravity(
108+
context: context,
109+
width: 250.0,
110+
doubleButtonGravity: Gravity.right,
111+
);
112+
}),
113+
makeTextButton("center", () {
114+
YYAlertDialogWithGravity(
115+
context: context,
116+
width: 250.0,
117+
doubleButtonGravity: Gravity.center,
118+
);
119+
}),
93120
],
94121
),
95122
],
@@ -110,7 +137,7 @@ showListViewDialog(BuildContext context) {
110137
makeTextButton("listTile", () {
111138
YYListViewDialogListTile(context);
112139
}),
113-
makeTextButton("listButton", () {
140+
makeTextButton("listRadio", () {
114141
YYListViewDialogListButton(context);
115142
}),
116143
],
@@ -121,10 +148,15 @@ showListViewDialog(BuildContext context) {
121148
}
122149

123150
Widget makeTextButton(title, Function() function) {
124-
return RaisedButton(
125-
onPressed: () {
126-
function();
127-
},
128-
child: Text(title),
151+
return SizedBox(
152+
width: 70.0,
153+
height: 35.0,
154+
child: RaisedButton(
155+
padding: EdgeInsets.all(0.0),
156+
onPressed: () {
157+
function();
158+
},
159+
child: Text(title),
160+
),
129161
);
130162
}

lib/components/alert_dialog.dart

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ YYDialog YYAlertDialogHeadAndBody(BuildContext context) {
4646
fontSize: 15.0,
4747
)
4848
..doubleButton(
49-
padding: EdgeInsets.only(top: 24.0),
49+
padding: EdgeInsets.only(top: 20.0),
5050
gravity: Gravity.right,
5151
text1: "DISAGREE",
5252
color1: Colors.deepPurpleAccent,
@@ -64,7 +64,37 @@ YYDialog YYAlertDialogHeadAndBody(BuildContext context) {
6464
..show();
6565
}
6666

67-
YYDialog YYAlertDialogWithGravity({context, width, gravity}) {
67+
YYDialog YYAlertDialogWithDivider(BuildContext context) {
68+
return YYDialog().build(context)
69+
..width = 220
70+
..borderRadius = 4.0
71+
..text(
72+
padding: EdgeInsets.all(25.0),
73+
alignment: Alignment.center,
74+
text: "确定要退出登录吗?",
75+
color: Colors.black,
76+
fontSize: 14.0,
77+
fontWeight: FontWeight.w500,
78+
)
79+
..divider()
80+
..doubleButton(
81+
padding: EdgeInsets.only(top: 10.0),
82+
gravity: Gravity.center,
83+
withDivider: true,
84+
text1: "取消",
85+
color1: Colors.redAccent,
86+
fontSize1: 14.0,
87+
fontWeight1: FontWeight.bold,
88+
text2: "确定",
89+
color2: Colors.redAccent,
90+
fontSize2: 14.0,
91+
fontWeight2: FontWeight.bold,
92+
)
93+
..show();
94+
}
95+
96+
YYDialog YYAlertDialogWithGravity(
97+
{context, width, gravity, doubleButtonGravity}) {
6898
return YYDialog().build(context)
6999
..width = width
70100
..gravity = gravity
@@ -84,8 +114,8 @@ YYDialog YYAlertDialogWithGravity({context, width, gravity}) {
84114
fontSize: 15.0,
85115
)
86116
..doubleButton(
87-
padding: EdgeInsets.only(top: 24.0),
88-
gravity: Gravity.right,
117+
padding: EdgeInsets.only(top: 20.0),
118+
gravity: doubleButtonGravity ?? Gravity.right,
89119
text1: "DISAGREE",
90120
color1: Colors.deepPurpleAccent,
91121
fontSize1: 14.0,

lib/flutter_custom_dialog.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class YYDialog {
4747
YYDialog doubleButton({
4848
padding,
4949
gravity,
50+
height,
5051
isClickAutoDismiss = true, //点击按钮后自动关闭
52+
withDivider = false, //中间分割线
5153
text1,
5254
color1,
5355
fontSize1,
@@ -60,8 +62,8 @@ class YYDialog {
6062
onTap2,
6163
}) {
6264
return this.widget(
63-
Padding(
64-
padding: padding ?? EdgeInsets.all(0.0),
65+
SizedBox(
66+
height: height ?? 45.0,
6567
child: Row(
6668
mainAxisAlignment: getRowMainAxisAlignment(gravity),
6769
children: <Widget>[
@@ -82,6 +84,10 @@ class YYDialog {
8284
),
8385
),
8486
),
87+
Visibility(
88+
visible: withDivider,
89+
child: VerticalDivider(),
90+
),
8591
FlatButton(
8692
onPressed: () {
8793
if (onTap2 != null) onTap2();
@@ -308,7 +314,7 @@ class YYDialog {
308314
break;
309315
case Gravity.center:
310316
default:
311-
mainAxisAlignment = MainAxisAlignment.spaceAround;
317+
mainAxisAlignment = MainAxisAlignment.center;
312318
break;
313319
}
314320
return mainAxisAlignment;

0 commit comments

Comments
 (0)