diff --git a/CHANGELOG.md b/CHANGELOG.md index faf3749..2a6e983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,4 +85,8 @@ ## 1.0.21 -* Add SpaceEvenly Gravity \ No newline at end of file +* Add SpaceEvenly Gravity + +## 1.1.0 + +* Migrate to null safety \ No newline at end of file diff --git a/README.md b/README.md index 43bb340..5c827aa 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Global dialog function encapsulation, with a semantic way to fill the content in ```yaml dependencies: - flutter_custom_dialog: ^1.0.21 + flutter_custom_dialog: ^1.1.0 ``` **2、import** diff --git a/README_CN.md b/README_CN.md index 2534ac4..4aec0e9 100644 --- a/README_CN.md +++ b/README_CN.md @@ -15,7 +15,7 @@ ```yaml dependencies: - flutter_custom_dialog: ^1.0.21 + flutter_custom_dialog: ^1.1.0 ``` **2、import** diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 0f072fd..f382161 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_custom_dialog","path":"C:\\\\YYLive4-OpenSource\\\\flutter-custom-dialog\\\\","dependencies":[]}],"android":[{"name":"flutter_custom_dialog","path":"C:\\\\YYLive4-OpenSource\\\\flutter-custom-dialog\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_custom_dialog","dependencies":[]}],"date_created":"2021-08-16 18:33:17.928565","version":"2.2.3"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_custom_dialog","path":"C:\\\\YYLive4-OpenSource\\\\flutter-custom-dialog\\\\","dependencies":[]}],"android":[{"name":"flutter_custom_dialog","path":"C:\\\\YYLive4-OpenSource\\\\flutter-custom-dialog\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_custom_dialog","dependencies":[]}],"date_created":"2021-08-16 20:01:06.563734","version":"2.2.3"} \ No newline at end of file diff --git a/example/pubspec.lock b/example/pubspec.lock index f90a913..e9049b7 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -158,4 +158,3 @@ packages: version: "2.1.0" sdks: dart: ">=2.12.0 <3.0.0" - flutter: ">=1.12.0" diff --git a/lib/flutter_custom_dialog.dart b/lib/flutter_custom_dialog.dart index 1bfac6f..598eb6a 100644 --- a/lib/flutter_custom_dialog.dart +++ b/lib/flutter_custom_dialog.dart @@ -7,17 +7,17 @@ export 'package:flutter_custom_dialog/flutter_custom_dialog.dart'; class YYDialog { //================================弹窗属性====================================== List widgetList = []; //弹窗内部所有组件 - static BuildContext _context; //弹窗上下文 - BuildContext context; //弹窗上下文 + static BuildContext? _context; //弹窗上下文 + BuildContext? context; //弹窗上下文 - double width; //弹窗宽度 - double height; //弹窗高度 + double? width; //弹窗宽度 + double? height; //弹窗高度 Duration duration = Duration(milliseconds: 250); //弹窗动画出现的时间 Gravity gravity = Gravity.center; //弹窗出现的位置 bool gravityAnimationEnable = false; //弹窗出现的位置带有的默认动画是否可用 Color barrierColor = Colors.black.withOpacity(.3); //弹窗外的背景色 - BoxConstraints constraints; //弹窗约束 - Function(Widget child, Animation animation) animatedFunc; //弹窗出现的动画 + BoxConstraints? constraints; //弹窗约束 + Function(Widget child, Animation animation)? animatedFunc; //弹窗出现的动画 bool barrierDismissible = true; //是否点击弹出外部消失 EdgeInsets margin = EdgeInsets.all(0.0); //弹窗布局的外边距 @@ -26,12 +26,12 @@ class YYDialog { /// @params useRootNavigator=true,push是用的嵌套根布局的context bool useRootNavigator = true; - Decoration decoration; //弹窗内的装饰,与backgroundColor和borderRadius互斥 + Decoration? decoration; //弹窗内的装饰,与backgroundColor和borderRadius互斥 Color backgroundColor = Colors.white; //弹窗内的背景色 double borderRadius = 0.0; //弹窗圆角 - Function() showCallBack; //展示的回调 - Function() dismissCallBack; //消失的回调 + Function()? showCallBack; //展示的回调 + Function()? dismissCallBack; //消失的回调 get isShowing => _isShowing; //当前 弹窗是否可见 bool _isShowing = false; @@ -41,7 +41,7 @@ class YYDialog { _context = ctx; } - YYDialog build([BuildContext ctx]) { + YYDialog build([BuildContext? ctx]) { if (ctx == null && _context != null) { this.context = _context; return this; @@ -101,7 +101,7 @@ class YYDialog { fontSize1, fontWeight1, fontFamily1, - VoidCallback onTap1, + VoidCallback? onTap1, buttonPadding1 = const EdgeInsets.all(0.0), text2, color2, @@ -164,10 +164,10 @@ class YYDialog { } YYDialog listViewOfListTile({ - List items, - double height, + List? items, + double? height, isClickAutoDismiss = true, - Function(int) onClickItemListener, + Function(int)? onClickItemListener, }) { return this.widget( Container( @@ -175,7 +175,7 @@ class YYDialog { child: ListView.builder( padding: EdgeInsets.all(0.0), shrinkWrap: true, - itemCount: items.length, + itemCount: items?.length ?? 0, itemBuilder: (BuildContext context, int index) { return Material( color: Colors.white, @@ -189,15 +189,15 @@ class YYDialog { dismiss(); } }, - contentPadding: items[index].padding ?? EdgeInsets.all(0.0), - leading: items[index].leading, + contentPadding: items?[index].padding ?? EdgeInsets.all(0.0), + leading: items?[index].leading, title: Text( - items[index].text ?? "", + items?[index].text ?? "", style: TextStyle( - color: items[index].color ?? null, - fontSize: items[index].fontSize ?? null, - fontWeight: items[index].fontWeight, - fontFamily: items[index].fontFamily, + color: items?[index].color ?? null, + fontSize: items?[index].fontSize ?? null, + fontWeight: items?[index].fontWeight, + fontFamily: items?[index].fontFamily, ), ), ), @@ -210,14 +210,14 @@ class YYDialog { } YYDialog listViewOfRadioButton({ - List items, - double height, - Color color, - Color activeColor, - int intialValue, - Function(int) onClickItemListener, + List? items, + double? height, + Color? color, + Color? activeColor, + int? intialValue, + Function(int)? onClickItemListener, }) { - Size size = MediaQuery.of(context).size; + Size size = MediaQuery.of(context!).size; return this.widget( Container( height: height, @@ -270,7 +270,7 @@ class YYDialog { CustomDialog( gravity: gravity, gravityAnimationEnable: gravityAnimationEnable, - context: this.context, + context: this.context!, barrierColor: barrierColor, animatedFunc: animatedFunc, barrierDismissible: barrierDismissible, @@ -300,13 +300,9 @@ class YYDialog { isShowingChange: (bool isShowingChange) { // showing or dismiss Callback if (isShowingChange) { - if (showCallBack != null) { - showCallBack(); - } + showCallBack?.call(); } else { - if (dismissCallBack != null) { - dismissCallBack(); - } + dismissCallBack?.call(); } _isShowing = isShowingChange; }, @@ -321,7 +317,7 @@ class YYDialog { void dismiss() { if (_isShowing) { - Navigator.of(context, rootNavigator: useRootNavigator).pop(); + Navigator.of(context!, rootNavigator: useRootNavigator).pop(); } } @@ -403,7 +399,7 @@ class YYDialog { ///弹窗的内容作为可变组件 class CustomDialogChildren extends StatefulWidget { final List widgetList; //弹窗内部所有组件 - final Function(bool) isShowingChange; + final Function(bool)? isShowingChange; CustomDialogChildren({this.widgetList = const [], this.isShowingChange}); @@ -414,7 +410,9 @@ class CustomDialogChildren extends StatefulWidget { class CustomDialogChildState extends State { @override Widget build(BuildContext context) { - widget.isShowingChange(true); + if (widget.isShowingChange != null) { + widget.isShowingChange!(true); + } return Column( children: widget.widgetList, ); @@ -422,7 +420,9 @@ class CustomDialogChildState extends State { @override void dispose() { - widget.isShowingChange(false); + if (widget.isShowingChange != null) { + widget.isShowingChange!(false); + } super.dispose(); } } @@ -431,24 +431,24 @@ class CustomDialogChildState extends State { class CustomDialog { BuildContext _context; Widget _child; - Duration _duration; - Color _barrierColor; - RouteTransitionsBuilder _transitionsBuilder; - bool _barrierDismissible; - Gravity _gravity; + Duration? _duration; + Color? _barrierColor; + RouteTransitionsBuilder? _transitionsBuilder; + bool? _barrierDismissible; + Gravity? _gravity; bool _gravityAnimationEnable; - Function _animatedFunc; + Function? _animatedFunc; CustomDialog({ - @required Widget child, - @required BuildContext context, - Duration duration, - Color barrierColor, - RouteTransitionsBuilder transitionsBuilder, - Gravity gravity, - bool gravityAnimationEnable, - Function animatedFunc, - bool barrierDismissible, + required Widget child, + required BuildContext context, + Duration? duration, + Color? barrierColor, + RouteTransitionsBuilder? transitionsBuilder, + Gravity? gravity, + bool gravityAnimationEnable = false, + Function? animatedFunc, + bool? barrierDismissible, }) : _child = child, _context = context, _gravity = gravity, @@ -531,7 +531,7 @@ class CustomDialog { //自定义动画 if (_animatedFunc != null) { - return _animatedFunc(child, animation); + return _animatedFunc!(child, animation); } //不需要默认动画 @@ -576,13 +576,13 @@ class ListTileItem { this.fontFamily, }); - EdgeInsets padding; - Widget leading; - String text; - Color color; - double fontSize; - FontWeight fontWeight; - String fontFamily; + EdgeInsets? padding; + Widget? leading; + String? text; + Color? color; + double? fontSize; + FontWeight? fontWeight; + String? fontFamily; } class RadioItem { @@ -595,11 +595,11 @@ class RadioItem { this.onTap, }); - EdgeInsets padding; - String text; - Color color; - double fontSize; - FontWeight fontWeight; - Function(int) onTap; + EdgeInsets? padding; + String? text; + Color? color; + double? fontSize; + FontWeight? fontWeight; + Function(int)? onTap; } //============================================================================ diff --git a/lib/flutter_custom_dialog_widget.dart b/lib/flutter_custom_dialog_widget.dart index 047f723..9114a9d 100644 --- a/lib/flutter_custom_dialog_widget.dart +++ b/lib/flutter_custom_dialog_widget.dart @@ -7,7 +7,7 @@ export 'package:flutter_custom_dialog/flutter_custom_dialog_widget.dart'; class YYRadioListTile extends StatefulWidget { YYRadioListTile({ - Key key, + Key? key, this.items, this.intialValue, this.color, @@ -16,11 +16,11 @@ class YYRadioListTile extends StatefulWidget { }) : assert(items != null), super(key: key); - final List items; - final Color color; - final Color activeColor; + final List? items; + final Color? color; + final Color? activeColor; final intialValue; - final Function(int) onChanged; + final Function(int)? onChanged; @override State createState() { @@ -47,25 +47,28 @@ class YYRadioListTileState extends State { return ListView.builder( padding: EdgeInsets.all(0.0), shrinkWrap: true, - itemCount: widget.items.length, + itemCount: widget.items?.length ?? 0, itemBuilder: (BuildContext context, int index) { return Material( color: widget.color, child: RadioListTile( title: Text( - widget.items[index].text, + widget.items?[index].text ?? "", style: TextStyle( - fontSize: widget.items[index].fontSize, - fontWeight: widget.items[index].fontWeight, - color: widget.items[index].color), + fontSize: widget.items?[index].fontSize ?? 14, + fontWeight: + widget.items?[index].fontWeight ?? FontWeight.normal, + color: widget.items?[index].color ?? Colors.black), ), value: index, groupValue: groupId, activeColor: widget.activeColor, - onChanged: (int value) { + onChanged: (int? value) { setState(() { - widget.onChanged(value); - groupId = value; + if (widget.onChanged != null) { + widget.onChanged!(value ?? 0); + } + groupId = value ?? -1; }); }, ), diff --git a/pubspec.lock b/pubspec.lock index e9ed765..ad6d1df 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -144,4 +144,3 @@ packages: version: "2.1.0" sdks: dart: ">=2.12.0 <3.0.0" - flutter: ">=1.12.0" diff --git a/pubspec.yaml b/pubspec.yaml index 940d09c..290ddc0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: flutter_custom_dialog description: Semantic dialog | Made In YY.inc | Welcome to contribute -version: 1.0.21 +version: 1.1.0 homepage: https://github.com/YYFlutter/flutter-custom-dialog.git publish_to: 'https://pub.dev' environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" flutter: ">=1.10.0" dependencies: