Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc8b3d8

Browse files
author
xuyingjun
committed
无Context也能使用[v1.0.4]
1 parent d1f2580 commit bc8b3d8

File tree

5 files changed

+81
-97
lines changed

5 files changed

+81
-97
lines changed

‎example/lib/main.dart‎

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
library flutter_custom_dialog;
22

33
import 'package:flutter/material.dart';
4-
import 'package:flutter_custom_dialog/flutter_custom_dialog.dart';
5-
import 'package:flutter_custom_dialog/components/example/alert_dialog.dart';
64
import 'package:flutter_custom_dialog/components/bean/dialog_gravity.dart';
5+
import 'package:flutter_custom_dialog/components/example/alert_dialog.dart';
76
import 'package:flutter_custom_dialog/components/example/listview_dialog.dart';
87
import 'package:flutter_custom_dialog/components/example/progress_dialog.dart';
8+
import 'package:flutter_custom_dialog/flutter_custom_dialog.dart';
99

1010
void main() => runApp(MyApp());
1111

@@ -23,19 +23,19 @@ class MyApp extends StatelessWidget {
2323
/*
2424
* When you init App, you can Initialize YYDialog so that use YYDialog.build().show() everywhere.
2525
*/
26-
2726
class AppHome extends StatelessWidget {
2827
Widget build(BuildContext context) {
29-
return YYDialog.init(
30-
Scaffold(
31-
appBar: AppBar(),
32-
body: SingleChildScrollView(
33-
child: Column(
34-
children: <Widget>[
35-
showAlertDialog(context),
36-
showDevelopDialog(context),
37-
],
38-
),
28+
//1、初始化context
29+
YYDialog.init(context);
30+
//2、后续使用可以不需要context
31+
return Scaffold(
32+
appBar: AppBar(),
33+
body: SingleChildScrollView(
34+
child: Column(
35+
children: <Widget>[
36+
showAlertDialog(context),
37+
showDevelopDialog(context),
38+
],
3939
),
4040
),
4141
);
@@ -53,55 +53,55 @@ showAlertDialog(BuildContext context) {
5353
Row(
5454
children: <Widget>[
5555
makeTextButton("body", () {
56-
YYAlertDialogBody(context);
56+
YYAlertDialogBody();
5757
}),
5858
makeTextButton("head&body", () {
59-
YYAlertDialogHeadAndBody(context);
59+
YYAlertDialogHeadAndBody();
6060
}),
6161
makeTextButton("divider", () {
62-
YYAlertDialogWithDivider(context);
62+
YYAlertDialogWithDivider();
6363
}),
6464
makeTextButton("listTile", () {
65-
YYListViewDialogListTile(context);
65+
YYListViewDialogListTile();
6666
}),
6767
makeTextButton("listRadio", () {
68-
YYListViewDialogListRadio(context);
68+
YYListViewDialogListRadio();
6969
}),
7070
],
7171
),
7272
Row(
7373
children: <Widget>[
7474
makeTextButton("nobody", () {
75-
YYProgressDialogNoBody(context);
75+
YYProgressDialogNoBody();
7676
}),
7777
makeTextButton("body", () {
78-
YYProgressDialogBody(context);
78+
YYProgressDialogBody();
7979
}),
8080
makeTextButton("pop\nmenu", () {
81-
YYAlertDialogPopMenu(context);
81+
YYAlertDialogPopMenu();
8282
}),
8383
makeTextButton("custom\nx&y", () {
84-
YYAlertDialogCustomXY(context);
84+
YYAlertDialogCustomXY();
8585
}),
8686
],
8787
),
8888
Text("2、dialog property"),
8989
Row(
9090
children: <Widget>[
9191
makeTextButton("duration", () {
92-
YYAlertDialogWithDuration(context);
92+
YYAlertDialogWithDuration();
9393
}),
9494
makeTextButton("barrier\ncolor", () {
95-
YYAlertDialogWithbarrierColor(context, Colors.redAccent);
95+
YYAlertDialogWithbarrierColor(Colors.redAccent);
9696
}),
9797
makeTextButton("transparent\ncolor", () {
98-
YYAlertDialogWithbarrierColor(context, Colors.transparent);
98+
YYAlertDialogWithbarrierColor(Colors.transparent);
9999
}),
100100
makeTextButton("background\ncolor", () {
101-
YYAlertDialogWithBackgroundColor(context);
101+
YYAlertDialogWithBackgroundColor();
102102
}),
103103
makeTextButton("barrier\ndismiss", () {
104-
YYAlertDialogWithBarrierDismiss(context);
104+
YYAlertDialogWithBarrierDismiss();
105105
}),
106106
],
107107
),
@@ -110,33 +110,28 @@ showAlertDialog(BuildContext context) {
110110
children: <Widget>[
111111
makeTextButton("bottom", () {
112112
YYAlertDialogWithGravity(
113-
context: context,
114113
gravity: Gravity.bottom,
115114
);
116115
}),
117116
makeTextButton("top", () {
118117
YYAlertDialogWithGravity(
119-
context: context,
120118
gravity: Gravity.top,
121119
);
122120
}),
123121
makeTextButton("left", () {
124122
YYAlertDialogWithGravity(
125-
context: context,
126123
width: 250.0,
127124
gravity: Gravity.left,
128125
);
129126
}),
130127
makeTextButton("right", () {
131128
YYAlertDialogWithGravity(
132-
context: context,
133129
width: 250.0,
134130
gravity: Gravity.right,
135131
);
136132
}),
137133
makeTextButton("center", () {
138134
YYAlertDialogWithGravity(
139-
context: context,
140135
width: 250.0,
141136
gravity: Gravity.center,
142137
);
@@ -147,28 +142,24 @@ showAlertDialog(BuildContext context) {
147142
children: <Widget>[
148143
makeTextButton("left\nbottom", () {
149144
YYAlertDialogWithGravity(
150-
context: context,
151145
width: 250.0,
152146
gravity: Gravity.leftBottom,
153147
);
154148
}),
155149
makeTextButton("left\ntop", () {
156150
YYAlertDialogWithGravity(
157-
context: context,
158151
width: 250.0,
159152
gravity: Gravity.leftTop,
160153
);
161154
}),
162155
makeTextButton("right\nbottom", () {
163156
YYAlertDialogWithGravity(
164-
context: context,
165157
width: 250.0,
166158
gravity: Gravity.rightBottom,
167159
);
168160
}),
169161
makeTextButton("right\ntop", () {
170162
YYAlertDialogWithGravity(
171-
context: context,
172163
width: 250.0,
173164
gravity: Gravity.rightTop,
174165
);
@@ -180,21 +171,18 @@ showAlertDialog(BuildContext context) {
180171
children: <Widget>[
181172
makeTextButton("left", () {
182173
YYAlertDialogWithGravity(
183-
context: context,
184174
width: 250.0,
185175
doubleButtonGravity: Gravity.left,
186176
);
187177
}),
188178
makeTextButton("right", () {
189179
YYAlertDialogWithGravity(
190-
context: context,
191180
width: 250.0,
192181
doubleButtonGravity: Gravity.right,
193182
);
194183
}),
195184
makeTextButton("center", () {
196185
YYAlertDialogWithGravity(
197-
context: context,
198186
width: 250.0,
199187
doubleButtonGravity: Gravity.center,
200188
);
@@ -205,16 +193,16 @@ showAlertDialog(BuildContext context) {
205193
Row(
206194
children: <Widget>[
207195
makeTextButton("scaleIn", () {
208-
YYAlertDialogWithScaleIn(context);
196+
YYAlertDialogWithScaleIn();
209197
}),
210198
makeTextButton("fadeIn", () {
211-
YYAlertDialogWithFadeIn(context);
199+
YYAlertDialogWithFadeIn();
212200
}),
213201
makeTextButton("rotateIn", () {
214-
YYAlertDialogWithRotateIn(context);
202+
YYAlertDialogWithRotateIn();
215203
}),
216204
makeTextButton("customIn", () {
217-
YYAlertDialogWithCustomIn(context);
205+
YYAlertDialogWithCustomIn();
218206
}),
219207
],
220208
),
@@ -246,7 +234,7 @@ showDevelopDialog(BuildContext context) {
246234
body: Column(
247235
children: <Widget>[
248236
makeTextButton("show", () {
249-
yyDialog = YYAlertDialogBody(context);
237+
yyDialog = YYAlertDialogBody();
250238
}),
251239
makeTextButton("dismiss", () {
252240
yyDialog?.dismiss();

‎lib/components/example/alert_dialog.dart‎

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_custom_dialog/components/bean/dialog_gravity.dart';
33
import 'package:flutter_custom_dialog/flutter_custom_dialog.dart';
44

5-
YYDialog YYAlertDialogBody(BuildContext context) {
6-
return YYDialog().build(context)
5+
YYDialog YYAlertDialogBody() {
6+
return YYDialog().build()
77
..width = 240
88
..borderRadius = 4.0
99
..text(
@@ -26,8 +26,8 @@ YYDialog YYAlertDialogBody(BuildContext context) {
2626
..show();
2727
}
2828

29-
YYDialog YYAlertDialogHeadAndBody(BuildContext context) {
30-
return YYDialog().build(context)
29+
YYDialog YYAlertDialogHeadAndBody() {
30+
return YYDialog().build()
3131
..width = 260
3232
..borderRadius = 4.0
3333
..text(
@@ -63,8 +63,8 @@ YYDialog YYAlertDialogHeadAndBody(BuildContext context) {
6363
..show();
6464
}
6565

66-
YYDialog YYAlertDialogWithDivider(BuildContext context) {
67-
return YYDialog().build(context)
66+
YYDialog YYAlertDialogWithDivider() {
67+
return YYDialog().build()
6868
..width = 220
6969
..borderRadius = 4.0
7070
..text(
@@ -98,8 +98,8 @@ YYDialog YYAlertDialogWithDivider(BuildContext context) {
9898
..show();
9999
}
100100

101-
YYDialog YYAlertDialogWithDuration(BuildContext context) {
102-
return YYDialog().build(context)
101+
YYDialog YYAlertDialogWithDuration() {
102+
return YYDialog().build()
103103
..width = 240
104104
..borderRadius = 4.0
105105
..gravityAnimationEnable = true
@@ -130,8 +130,8 @@ YYDialog YYAlertDialogWithDuration(BuildContext context) {
130130
..show();
131131
}
132132

133-
YYDialog YYAlertDialogWithbarrierColor(BuildContext context, Color color) {
134-
return YYDialog().build(context)
133+
YYDialog YYAlertDialogWithbarrierColor(Color color) {
134+
return YYDialog().build()
135135
..width = 240
136136
..borderRadius = 4.0
137137
..barrierColor = color
@@ -160,8 +160,8 @@ YYDialog YYAlertDialogWithbarrierColor(BuildContext context, Color color) {
160160
..show();
161161
}
162162

163-
YYDialog YYAlertDialogWithBackgroundColor(BuildContext context) {
164-
return YYDialog().build(context)
163+
YYDialog YYAlertDialogWithBackgroundColor() {
164+
return YYDialog().build()
165165
..width = 240
166166
..borderRadius = 4.0
167167
..backgroundColor = Colors.yellow
@@ -190,8 +190,8 @@ YYDialog YYAlertDialogWithBackgroundColor(BuildContext context) {
190190
..show();
191191
}
192192

193-
YYDialog YYAlertDialogWithBarrierDismiss(BuildContext context) {
194-
return YYDialog().build(context)
193+
YYDialog YYAlertDialogWithBarrierDismiss() {
194+
return YYDialog().build()
195195
..width = 240
196196
..borderRadius = 4.0
197197
..barrierDismissible = false
@@ -220,9 +220,8 @@ YYDialog YYAlertDialogWithBarrierDismiss(BuildContext context) {
220220
..show();
221221
}
222222

223-
YYDialog YYAlertDialogWithGravity(
224-
{context, width, gravity, doubleButtonGravity}) {
225-
return YYDialog().build(context)
223+
YYDialog YYAlertDialogWithGravity({width, gravity, doubleButtonGravity}) {
224+
return YYDialog().build()
226225
..width = width
227226
..gravity = gravity
228227
..gravityAnimationEnable = true
@@ -254,8 +253,8 @@ YYDialog YYAlertDialogWithGravity(
254253
..show();
255254
}
256255

257-
YYDialog YYAlertDialogWithScaleIn(BuildContext context) {
258-
return YYDialog().build(context)
256+
YYDialog YYAlertDialogWithScaleIn() {
257+
return YYDialog().build()
259258
..width = 240
260259
..borderRadius = 4.0
261260
..duration = Duration(milliseconds: 500)
@@ -290,8 +289,8 @@ YYDialog YYAlertDialogWithScaleIn(BuildContext context) {
290289
..show();
291290
}
292291

293-
YYDialog YYAlertDialogWithFadeIn(BuildContext context) {
294-
return YYDialog().build(context)
292+
YYDialog YYAlertDialogWithFadeIn() {
293+
return YYDialog().build()
295294
..width = 240
296295
..borderRadius = 4.0
297296
..duration = Duration(milliseconds: 500)
@@ -326,8 +325,8 @@ YYDialog YYAlertDialogWithFadeIn(BuildContext context) {
326325
..show();
327326
}
328327

329-
YYDialog YYAlertDialogWithRotateIn(BuildContext context) {
330-
return YYDialog().build(context)
328+
YYDialog YYAlertDialogWithRotateIn() {
329+
return YYDialog().build()
331330
..width = 240
332331
..borderRadius = 4.0
333332
..duration = Duration(milliseconds: 500)
@@ -362,8 +361,8 @@ YYDialog YYAlertDialogWithRotateIn(BuildContext context) {
362361
..show();
363362
}
364363

365-
YYDialog YYAlertDialogWithCustomIn(BuildContext context) {
366-
return YYDialog().build(context)
364+
YYDialog YYAlertDialogWithCustomIn() {
365+
return YYDialog().build()
367366
..width = 240
368367
..borderRadius = 4.0
369368
..duration = Duration(milliseconds: 500)
@@ -414,8 +413,8 @@ YYDialog YYAlertDialogWithCustomIn(BuildContext context) {
414413
..show();
415414
}
416415

417-
YYDialog YYDialogDemo(BuildContext context) {
418-
return YYDialog().build(context)
416+
YYDialog YYDialogDemo() {
417+
return YYDialog().build()
419418
..width = 220
420419
..height = 500
421420
..barrierColor = Colors.black.withOpacity(.3)
@@ -445,8 +444,8 @@ YYDialog YYDialogDemo(BuildContext context) {
445444
..show();
446445
}
447446

448-
YYDialog YYAlertDialogPopMenu(BuildContext context) {
449-
return YYDialog().build(context)
447+
YYDialog YYAlertDialogPopMenu() {
448+
return YYDialog().build()
450449
..width = 120
451450
..borderRadius = 8.0
452451
..gravity = Gravity.rightTop
@@ -467,8 +466,8 @@ YYDialog YYAlertDialogPopMenu(BuildContext context) {
467466
..show();
468467
}
469468

470-
YYDialog YYAlertDialogCustomXY(BuildContext context) {
471-
return YYDialog().build(context)
469+
YYDialog YYAlertDialogCustomXY() {
470+
return YYDialog().build()
472471
..width = 120
473472
..borderRadius = 8.0
474473
..barrierColor = Colors.transparent

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /