@@ -7,17 +7,17 @@ export 'package:flutter_custom_dialog/flutter_custom_dialog.dart';
77class YYDialog {
88 //================================弹窗属性======================================
99 List <Widget > widgetList = []; //弹窗内部所有组件
10- static BuildContext _context; //弹窗上下文
11- BuildContext context; //弹窗上下文
10+ static BuildContext ? _context; //弹窗上下文
11+ BuildContext ? context; //弹窗上下文
1212
13- double width; //弹窗宽度
14- double height; //弹窗高度
13+ double ? width; //弹窗宽度
14+ double ? height; //弹窗高度
1515 Duration duration = Duration (milliseconds: 250 ); //弹窗动画出现的时间
1616 Gravity gravity = Gravity .center; //弹窗出现的位置
1717 bool gravityAnimationEnable = false ; //弹窗出现的位置带有的默认动画是否可用
1818 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; //弹窗出现的动画
2121 bool barrierDismissible = true ; //是否点击弹出外部消失
2222 EdgeInsets margin = EdgeInsets .all (0.0 ); //弹窗布局的外边距
2323
@@ -26,12 +26,12 @@ class YYDialog {
2626 /// @params useRootNavigator=true,push是用的嵌套根布局的context
2727 bool useRootNavigator = true ;
2828
29- Decoration decoration; //弹窗内的装饰,与backgroundColor和borderRadius互斥
29+ Decoration ? decoration; //弹窗内的装饰,与backgroundColor和borderRadius互斥
3030 Color backgroundColor = Colors .white; //弹窗内的背景色
3131 double borderRadius = 0.0 ; //弹窗圆角
3232
33- Function () showCallBack; //展示的回调
34- Function () dismissCallBack; //消失的回调
33+ Function ()? showCallBack; //展示的回调
34+ Function ()? dismissCallBack; //消失的回调
3535
3636 get isShowing => _isShowing; //当前 弹窗是否可见
3737 bool _isShowing = false ;
@@ -41,7 +41,7 @@ class YYDialog {
4141 _context = ctx;
4242 }
4343
44- YYDialog build ([BuildContext ctx]) {
44+ YYDialog build ([BuildContext ? ctx]) {
4545 if (ctx == null && _context != null ) {
4646 this .context = _context;
4747 return this ;
@@ -101,7 +101,7 @@ class YYDialog {
101101 fontSize1,
102102 fontWeight1,
103103 fontFamily1,
104- VoidCallback onTap1,
104+ VoidCallback ? onTap1,
105105 buttonPadding1 = const EdgeInsets .all (0.0 ),
106106 text2,
107107 color2,
@@ -164,18 +164,18 @@ class YYDialog {
164164 }
165165
166166 YYDialog listViewOfListTile ({
167- List <ListTileItem > items,
168- double height,
167+ List <ListTileItem >? items,
168+ double ? height,
169169 isClickAutoDismiss = true ,
170- Function (int ) onClickItemListener,
170+ Function (int )? onClickItemListener,
171171 }) {
172172 return this .widget (
173173 Container (
174174 height: height,
175175 child: ListView .builder (
176176 padding: EdgeInsets .all (0.0 ),
177177 shrinkWrap: true ,
178- itemCount: items.length,
178+ itemCount: items? .length ?? 0 ,
179179 itemBuilder: (BuildContext context, int index) {
180180 return Material (
181181 color: Colors .white,
@@ -189,15 +189,15 @@ class YYDialog {
189189 dismiss ();
190190 }
191191 },
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,
194194 title: Text (
195- items[index].text ?? "" ,
195+ items? [index].text ?? "" ,
196196 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,
201201 ),
202202 ),
203203 ),
@@ -210,14 +210,14 @@ class YYDialog {
210210 }
211211
212212 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,
219219 }) {
220- Size size = MediaQuery .of (context).size;
220+ Size size = MediaQuery .of (context! ).size;
221221 return this .widget (
222222 Container (
223223 height: height,
@@ -270,7 +270,7 @@ class YYDialog {
270270 CustomDialog (
271271 gravity: gravity,
272272 gravityAnimationEnable: gravityAnimationEnable,
273- context: this .context,
273+ context: this .context! ,
274274 barrierColor: barrierColor,
275275 animatedFunc: animatedFunc,
276276 barrierDismissible: barrierDismissible,
@@ -300,13 +300,9 @@ class YYDialog {
300300 isShowingChange: (bool isShowingChange) {
301301 // showing or dismiss Callback
302302 if (isShowingChange) {
303- if (showCallBack != null ) {
304- showCallBack ();
305- }
303+ showCallBack? .call ();
306304 } else {
307- if (dismissCallBack != null ) {
308- dismissCallBack ();
309- }
305+ dismissCallBack? .call ();
310306 }
311307 _isShowing = isShowingChange;
312308 },
@@ -321,7 +317,7 @@ class YYDialog {
321317
322318 void dismiss () {
323319 if (_isShowing) {
324- Navigator .of (context, rootNavigator: useRootNavigator).pop ();
320+ Navigator .of (context! , rootNavigator: useRootNavigator).pop ();
325321 }
326322 }
327323
@@ -403,7 +399,7 @@ class YYDialog {
403399///弹窗的内容作为可变组件
404400class CustomDialogChildren extends StatefulWidget {
405401 final List <Widget > widgetList; //弹窗内部所有组件
406- final Function (bool ) isShowingChange;
402+ final Function (bool )? isShowingChange;
407403
408404 CustomDialogChildren ({this .widgetList = const [], this .isShowingChange});
409405
@@ -414,15 +410,19 @@ class CustomDialogChildren extends StatefulWidget {
414410class CustomDialogChildState extends State <CustomDialogChildren > {
415411 @override
416412 Widget build (BuildContext context) {
417- widget.isShowingChange (true );
413+ if (widget.isShowingChange != null ) {
414+ widget.isShowingChange !(true );
415+ }
418416 return Column (
419417 children: widget.widgetList,
420418 );
421419 }
422420
423421 @override
424422 void dispose () {
425- widget.isShowingChange (false );
423+ if (widget.isShowingChange != null ) {
424+ widget.isShowingChange !(false );
425+ }
426426 super .dispose ();
427427 }
428428}
@@ -431,24 +431,24 @@ class CustomDialogChildState extends State<CustomDialogChildren> {
431431class CustomDialog {
432432 BuildContext _context;
433433 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;
439439 bool _gravityAnimationEnable;
440- Function _animatedFunc;
440+ Function ? _animatedFunc;
441441
442442 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,
452452 }) : _child = child,
453453 _context = context,
454454 _gravity = gravity,
@@ -531,7 +531,7 @@ class CustomDialog {
531531
532532 //自定义动画
533533 if (_animatedFunc != null ) {
534- return _animatedFunc (child, animation);
534+ return _animatedFunc ! (child, animation);
535535 }
536536
537537 //不需要默认动画
@@ -576,13 +576,13 @@ class ListTileItem {
576576 this .fontFamily,
577577 });
578578
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;
586586}
587587
588588class RadioItem {
@@ -595,11 +595,11 @@ class RadioItem {
595595 this .onTap,
596596 });
597597
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;
604604}
605605//============================================================================
0 commit comments