@@ -7,17 +7,17 @@ export 'package:flutter_custom_dialog/flutter_custom_dialog.dart';
7
7
class YYDialog {
8
8
//================================弹窗属性======================================
9
9
List <Widget > widgetList = []; //弹窗内部所有组件
10
- static BuildContext _context; //弹窗上下文
11
- BuildContext context; //弹窗上下文
10
+ static BuildContext ? _context; //弹窗上下文
11
+ BuildContext ? context; //弹窗上下文
12
12
13
- double width; //弹窗宽度
14
- double height; //弹窗高度
13
+ double ? width; //弹窗宽度
14
+ double ? height; //弹窗高度
15
15
Duration duration = Duration (milliseconds: 250 ); //弹窗动画出现的时间
16
16
Gravity gravity = Gravity .center; //弹窗出现的位置
17
17
bool gravityAnimationEnable = false ; //弹窗出现的位置带有的默认动画是否可用
18
18
Color barrierColor = Colors .black.withOpacity (.3 ); //弹窗外的背景色
19
- BoxConstraints constraints; //弹窗约束
20
- Function (Widget child, Animation <double > animation) animatedFunc; //弹窗出现的动画
19
+ BoxConstraints ? constraints; //弹窗约束
20
+ Function (Widget child, Animation <double > animation)? animatedFunc; //弹窗出现的动画
21
21
bool barrierDismissible = true ; //是否点击弹出外部消失
22
22
EdgeInsets margin = EdgeInsets .all (0.0 ); //弹窗布局的外边距
23
23
@@ -26,12 +26,12 @@ class YYDialog {
26
26
/// @params useRootNavigator=true,push是用的嵌套根布局的context
27
27
bool useRootNavigator = true ;
28
28
29
- Decoration decoration; //弹窗内的装饰,与backgroundColor和borderRadius互斥
29
+ Decoration ? decoration; //弹窗内的装饰,与backgroundColor和borderRadius互斥
30
30
Color backgroundColor = Colors .white; //弹窗内的背景色
31
31
double borderRadius = 0.0 ; //弹窗圆角
32
32
33
- Function () showCallBack; //展示的回调
34
- Function () dismissCallBack; //消失的回调
33
+ Function ()? showCallBack; //展示的回调
34
+ Function ()? dismissCallBack; //消失的回调
35
35
36
36
get isShowing => _isShowing; //当前 弹窗是否可见
37
37
bool _isShowing = false ;
@@ -41,7 +41,7 @@ class YYDialog {
41
41
_context = ctx;
42
42
}
43
43
44
- YYDialog build ([BuildContext ctx]) {
44
+ YYDialog build ([BuildContext ? ctx]) {
45
45
if (ctx == null && _context != null ) {
46
46
this .context = _context;
47
47
return this ;
@@ -101,7 +101,7 @@ class YYDialog {
101
101
fontSize1,
102
102
fontWeight1,
103
103
fontFamily1,
104
- VoidCallback onTap1,
104
+ VoidCallback ? onTap1,
105
105
buttonPadding1 = const EdgeInsets .all (0.0 ),
106
106
text2,
107
107
color2,
@@ -164,18 +164,18 @@ class YYDialog {
164
164
}
165
165
166
166
YYDialog listViewOfListTile ({
167
- List <ListTileItem > items,
168
- double height,
167
+ List <ListTileItem >? items,
168
+ double ? height,
169
169
isClickAutoDismiss = true ,
170
- Function (int ) onClickItemListener,
170
+ Function (int )? onClickItemListener,
171
171
}) {
172
172
return this .widget (
173
173
Container (
174
174
height: height,
175
175
child: ListView .builder (
176
176
padding: EdgeInsets .all (0.0 ),
177
177
shrinkWrap: true ,
178
- itemCount: items.length,
178
+ itemCount: items? .length ?? 0 ,
179
179
itemBuilder: (BuildContext context, int index) {
180
180
return Material (
181
181
color: Colors .white,
@@ -189,15 +189,15 @@ class YYDialog {
189
189
dismiss ();
190
190
}
191
191
},
192
- contentPadding: items[index].padding ?? EdgeInsets .all (0.0 ),
193
- leading: items[index].leading,
192
+ contentPadding: items? [index].padding ?? EdgeInsets .all (0.0 ),
193
+ leading: items? [index].leading,
194
194
title: Text (
195
- items[index].text ?? "" ,
195
+ items? [index].text ?? "" ,
196
196
style: TextStyle (
197
- color: items[index].color ?? null ,
198
- fontSize: items[index].fontSize ?? null ,
199
- fontWeight: items[index].fontWeight,
200
- fontFamily: items[index].fontFamily,
197
+ color: items? [index].color ?? null ,
198
+ fontSize: items? [index].fontSize ?? null ,
199
+ fontWeight: items? [index].fontWeight,
200
+ fontFamily: items? [index].fontFamily,
201
201
),
202
202
),
203
203
),
@@ -210,14 +210,14 @@ class YYDialog {
210
210
}
211
211
212
212
YYDialog listViewOfRadioButton ({
213
- List <RadioItem > items,
214
- double height,
215
- Color color,
216
- Color activeColor,
217
- int intialValue,
218
- Function (int ) onClickItemListener,
213
+ List <RadioItem >? items,
214
+ double ? height,
215
+ Color ? color,
216
+ Color ? activeColor,
217
+ int ? intialValue,
218
+ Function (int )? onClickItemListener,
219
219
}) {
220
- Size size = MediaQuery .of (context).size;
220
+ Size size = MediaQuery .of (context! ).size;
221
221
return this .widget (
222
222
Container (
223
223
height: height,
@@ -270,7 +270,7 @@ class YYDialog {
270
270
CustomDialog (
271
271
gravity: gravity,
272
272
gravityAnimationEnable: gravityAnimationEnable,
273
- context: this .context,
273
+ context: this .context! ,
274
274
barrierColor: barrierColor,
275
275
animatedFunc: animatedFunc,
276
276
barrierDismissible: barrierDismissible,
@@ -300,13 +300,9 @@ class YYDialog {
300
300
isShowingChange: (bool isShowingChange) {
301
301
// showing or dismiss Callback
302
302
if (isShowingChange) {
303
- if (showCallBack != null ) {
304
- showCallBack ();
305
- }
303
+ showCallBack? .call ();
306
304
} else {
307
- if (dismissCallBack != null ) {
308
- dismissCallBack ();
309
- }
305
+ dismissCallBack? .call ();
310
306
}
311
307
_isShowing = isShowingChange;
312
308
},
@@ -321,7 +317,7 @@ class YYDialog {
321
317
322
318
void dismiss () {
323
319
if (_isShowing) {
324
- Navigator .of (context, rootNavigator: useRootNavigator).pop ();
320
+ Navigator .of (context! , rootNavigator: useRootNavigator).pop ();
325
321
}
326
322
}
327
323
@@ -403,7 +399,7 @@ class YYDialog {
403
399
///弹窗的内容作为可变组件
404
400
class CustomDialogChildren extends StatefulWidget {
405
401
final List <Widget > widgetList; //弹窗内部所有组件
406
- final Function (bool ) isShowingChange;
402
+ final Function (bool )? isShowingChange;
407
403
408
404
CustomDialogChildren ({this .widgetList = const [], this .isShowingChange});
409
405
@@ -414,15 +410,19 @@ class CustomDialogChildren extends StatefulWidget {
414
410
class CustomDialogChildState extends State <CustomDialogChildren > {
415
411
@override
416
412
Widget build (BuildContext context) {
417
- widget.isShowingChange (true );
413
+ if (widget.isShowingChange != null ) {
414
+ widget.isShowingChange !(true );
415
+ }
418
416
return Column (
419
417
children: widget.widgetList,
420
418
);
421
419
}
422
420
423
421
@override
424
422
void dispose () {
425
- widget.isShowingChange (false );
423
+ if (widget.isShowingChange != null ) {
424
+ widget.isShowingChange !(false );
425
+ }
426
426
super .dispose ();
427
427
}
428
428
}
@@ -431,24 +431,24 @@ class CustomDialogChildState extends State<CustomDialogChildren> {
431
431
class CustomDialog {
432
432
BuildContext _context;
433
433
Widget _child;
434
- Duration _duration;
435
- Color _barrierColor;
436
- RouteTransitionsBuilder _transitionsBuilder;
437
- bool _barrierDismissible;
438
- Gravity _gravity;
434
+ Duration ? _duration;
435
+ Color ? _barrierColor;
436
+ RouteTransitionsBuilder ? _transitionsBuilder;
437
+ bool ? _barrierDismissible;
438
+ Gravity ? _gravity;
439
439
bool _gravityAnimationEnable;
440
- Function _animatedFunc;
440
+ Function ? _animatedFunc;
441
441
442
442
CustomDialog ({
443
- @ required Widget child,
444
- @ required BuildContext context,
445
- Duration duration,
446
- Color barrierColor,
447
- RouteTransitionsBuilder transitionsBuilder,
448
- Gravity gravity,
449
- bool gravityAnimationEnable,
450
- Function animatedFunc,
451
- bool barrierDismissible,
443
+ required Widget child,
444
+ required BuildContext context,
445
+ Duration ? duration,
446
+ Color ? barrierColor,
447
+ RouteTransitionsBuilder ? transitionsBuilder,
448
+ Gravity ? gravity,
449
+ bool gravityAnimationEnable = false ,
450
+ Function ? animatedFunc,
451
+ bool ? barrierDismissible,
452
452
}) : _child = child,
453
453
_context = context,
454
454
_gravity = gravity,
@@ -531,7 +531,7 @@ class CustomDialog {
531
531
532
532
//自定义动画
533
533
if (_animatedFunc != null ) {
534
- return _animatedFunc (child, animation);
534
+ return _animatedFunc ! (child, animation);
535
535
}
536
536
537
537
//不需要默认动画
@@ -576,13 +576,13 @@ class ListTileItem {
576
576
this .fontFamily,
577
577
});
578
578
579
- EdgeInsets padding;
580
- Widget leading;
581
- String text;
582
- Color color;
583
- double fontSize;
584
- FontWeight fontWeight;
585
- String fontFamily;
579
+ EdgeInsets ? padding;
580
+ Widget ? leading;
581
+ String ? text;
582
+ Color ? color;
583
+ double ? fontSize;
584
+ FontWeight ? fontWeight;
585
+ String ? fontFamily;
586
586
}
587
587
588
588
class RadioItem {
@@ -595,11 +595,11 @@ class RadioItem {
595
595
this .onTap,
596
596
});
597
597
598
- EdgeInsets padding;
599
- String text;
600
- Color color;
601
- double fontSize;
602
- FontWeight fontWeight;
603
- Function (int ) onTap;
598
+ EdgeInsets ? padding;
599
+ String ? text;
600
+ Color ? color;
601
+ double ? fontSize;
602
+ FontWeight ? fontWeight;
603
+ Function (int )? onTap;
604
604
}
605
605
//============================================================================
0 commit comments