diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml index 5b80310..b54adb1 100644 --- a/.idea/libraries/Dart_SDK.xml +++ b/.idea/libraries/Dart_SDK.xml @@ -1,17 +1,26 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index dfda312..ceac72e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 01b7955..5100a54 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,214 +1,53 @@ + + + + + + + + + + + + + + + + + + + - - \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e1ec8ae..de32932 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,4 +57,44 @@ ## 1.0.14 -* remove log \ No newline at end of file +* remove log + +## 1.0.15 + +* add callback + +## 1.0.16 + +* add decoration property + +## 1.0.17 + +* add decoration property + +## 1.0.18 + +* add color property for listRadio + +## 1.0.19 + +* fix a padding bug + +## 1.0.20 + +* add a useRootNavigator property + +## 1.0.21 + +* Add SpaceEvenly Gravity + +## 1.1.0 + +* Migrate to null safety + +## 1.1.1 + +* try to fix Android V2 embedding + +## 1.2.0 + +* fix Android V2 embedding \ No newline at end of file diff --git a/README.md b/README.md index 42db5a3..ea40c23 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![pub package](https://img.shields.io/pub/v/flutter_custom_dialog.svg)](https://pub.dev/packages/flutter_custom_dialog) -**[Lanuage ~~]** [English](README.md) | [中文文档](README_CN.md) +**[Language ~~]** [English](README.md) | [中文文档](README_CN.md) Global dialog function encapsulation, with a semantic way to fill the content inside the dialog, the current function provided @@ -17,7 +17,7 @@ Global dialog function encapsulation, with a semantic way to fill the content in ```yaml dependencies: - flutter_custom_dialog: ^1.0.14 + flutter_custom_dialog: ^1.3.0 ``` **2、import** @@ -219,18 +219,42 @@ import 'package:flutter_custom_dialog/flutter_custom_dialog.dart'; dialog property Settings can be called through the method of member variables, as detailed in the following table ```dart -YYDialog YYDialogDemo(BuildContext context) { - return YYDialog().build(context) - ..width = 220 - ..height = 500 - ..barrierColor = Colors.black.withOpacity(.3) +YYDialog YYNoticeDialog() { + return YYDialog().build() + ..width = 120 + ..height = 110 + ..backgroundColor = Colors.black.withOpacity(0.8) + ..borderRadius = 10.0 + ..showCallBack = () { + print("showCallBack invoke"); + } + ..dismissCallBack = () { + print("dismissCallBack invoke"); + } + ..widget(Padding( + padding: EdgeInsets.only(top: 21), + child: Image.asset( + 'images/success.png', + width: 38, + height: 38, + ), + )) + ..widget(Padding( + padding: EdgeInsets.only(top: 10), + child: Text( + "Success", + style: TextStyle( + fontSize: 15, + color: Colors.white, + ), + ), + )) ..animatedFunc = (child, animation) { return ScaleTransition( child: child, scale: Tween(begin: 0.0, end: 1.0).animate(animation), ); } - ..borderRadius = 4.0 ..show(); } ``` @@ -246,11 +270,18 @@ gravity|Where the dialog appears|center gravityAnimationEnable|The dialog appears with the default animation available|false margin|The margin of a dialog|EdgeInsets.all(0.0) barrierColor|Dialog barrierColor|30% of black +decoration|Dialog decoration|null backgroundColor|Dialog backgroundColor|white borderRadius|Dialog borderRadius|0.0 constraints|Dialog constraints|no constraints animatedFunc|Animation of dialog|Emerge from the middle +showCallBack|dialog show callbacks|not +dismissCallBack|dialog dismiss callbacks|not barrierDismissible|Whether to click to pop up the external disappear|true +useRootNavigator|Whether to use root navigation|true + +* After setting gravity, set gravityAnimationEnable = true if animation is needed +* If the decoration property is set, the backgroundColor and borderRadius are not in effect; they are mutually exclusive Supported method diff --git a/README_CN.md b/README_CN.md index e8dfa79..f502f6c 100644 --- a/README_CN.md +++ b/README_CN.md @@ -15,7 +15,7 @@ ```yaml dependencies: - flutter_custom_dialog: ^1.0.14 + flutter_custom_dialog: ^1.3.0 ``` **2、import** @@ -217,18 +217,42 @@ import 'package:flutter_custom_dialog/flutter_custom_dialog.dart'; 弹窗的属性设置可以通过成员变量的方法去调用,具体详见下表 ```dart -YYDialog YYDialogDemo(BuildContext context) { - return YYDialog().build(context) - ..width = 220 - ..height = 500 - ..barrierColor = Colors.black.withOpacity(.3) +YYDialog YYNoticeDialog() { + return YYDialog().build() + ..width = 120 + ..height = 110 + ..backgroundColor = Colors.black.withOpacity(0.8) + ..borderRadius = 10.0 + ..showCallBack = () { + print("showCallBack invoke"); + } + ..dismissCallBack = () { + print("dismissCallBack invoke"); + } + ..widget(Padding( + padding: EdgeInsets.only(top: 21), + child: Image.asset( + 'images/success.png', + width: 38, + height: 38, + ), + )) + ..widget(Padding( + padding: EdgeInsets.only(top: 10), + child: Text( + "Success", + style: TextStyle( + fontSize: 15, + color: Colors.white, + ), + ), + )) ..animatedFunc = (child, animation) { return ScaleTransition( child: child, scale: Tween(begin: 0.0, end: 1.0).animate(animation), ); } - ..borderRadius = 4.0 ..show(); } ``` @@ -244,11 +268,18 @@ gravity|弹窗出现的位置|居中 gravityAnimationEnable|弹窗出现的位置带有的默认动画是否可用|false margin|弹窗的外边距|EdgeInsets.all(0.0) barrierColor|弹窗外的背景色|30%黑色 +decoration|弹窗内的装饰|null backgroundColor|弹窗内的背景色|白色 borderRadius|弹窗圆角|0.0 constraints|弹窗约束|无 animatedFunc|弹窗出现的动画|从中间出现 +showCallBack|弹窗展示的回调|无 +dismissCallBack|弹窗消失的回调|无 barrierDismissible|是否点击弹出外部消失|true +useRootNavigator|是否使用根导航|true + +* 设置完gravity后,若需要动画则设置gravityAnimationEnable = true +* 若设置decoration属性,则backgroundColor和borderRadius不生效,他们是互斥关系 支持的方法 diff --git a/android/build.gradle b/android/build.gradle index 464905f..4b2409a 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -25,7 +25,7 @@ android { compileSdkVersion 28 defaultConfig { - minSdkVersion 16 + minSdkVersion 20 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } lintOptions { diff --git a/android/gradle.properties b/android/gradle.properties index 2bd6f4f..e60119f 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,2 +1,4 @@ org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/android/src/main/java/yy/inc/flutter_custom_dialog/FlutterCustomDialogPlugin.java b/android/src/main/java/yy/inc/flutter_custom_dialog/FlutterCustomDialogPlugin.java index b708bf4..c901469 100644 --- a/android/src/main/java/yy/inc/flutter_custom_dialog/FlutterCustomDialogPlugin.java +++ b/android/src/main/java/yy/inc/flutter_custom_dialog/FlutterCustomDialogPlugin.java @@ -1,25 +1,35 @@ package yy.inc.flutter_custom_dialog; +import androidx.annotation.NonNull; + +import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.PluginRegistry.Registrar; /** FlutterCustomDialogPlugin */ -public class FlutterCustomDialogPlugin implements MethodCallHandler { - /** Plugin registration. */ - public static void registerWith(Registrar registrar) { - final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_custom_dialog"); - channel.setMethodCallHandler(new FlutterCustomDialogPlugin()); +public class FlutterCustomDialogPlugin implements FlutterPlugin, MethodCallHandler { + + private MethodChannel channel; + + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_custom_dialog"); + channel.setMethodCallHandler(this); } @Override - public void onMethodCall(MethodCall call, Result result) { + public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { if (call.method.equals("getPlatformVersion")) { result.success("Android " + android.os.Build.VERSION.RELEASE); } else { result.notImplemented(); } } + + @Override + public void onDetachedFromEngine(FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); + } } diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies new file mode 100644 index 0000000..b4f3407 --- /dev/null +++ b/example/.flutter-plugins-dependencies @@ -0,0 +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":"2022-09-08 10:51:06.169356","version":"2.5.3"} \ No newline at end of file diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 37e040a..29dbb25 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -34,7 +34,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "yy.inc.flutter_custom_dialog_example" - minSdkVersion 16 + minSdkVersion 20 targetSdkVersion 28 versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index a7cbfba..0063516 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -7,7 +7,6 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" /> + + diff --git a/example/android/app/src/main/java/yy/inc/flutter_custom_dialog_example/MainActivity.java b/example/android/app/src/main/java/yy/inc/flutter_custom_dialog_example/MainActivity.java index 5c5a420..eaf5cf2 100644 --- a/example/android/app/src/main/java/yy/inc/flutter_custom_dialog_example/MainActivity.java +++ b/example/android/app/src/main/java/yy/inc/flutter_custom_dialog_example/MainActivity.java @@ -1,13 +1,7 @@ package yy.inc.flutter_custom_dialog_example; -import android.os.Bundle; -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; +import io.flutter.embedding.android.FlutterActivity; public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + } diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml index 00fa441..9fa09fc 100644 --- a/example/android/app/src/main/res/values/styles.xml +++ b/example/android/app/src/main/res/values/styles.xml @@ -5,4 +5,8 @@ Flutter draws its first frame --> @drawable/launch_background + + diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 2bd6f4f..94adc3a 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,2 +1,3 @@ org.gradle.jvmargs=-Xmx1536M - +android.useAndroidX=true +android.enableJetifier=true diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 29b4ef4..a6ae7d7 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,8 +1,13 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=C:\FlutterSDK\flutter" -export "FLUTTER_APPLICATION_PATH=C:\YYLive4-OpenSource\flutter-custom-dialog\flutter_custom_dialog\example" +export "FLUTTER_ROOT=G:\flutter" +export "FLUTTER_APPLICATION_PATH=C:\YYLive4-OpenSource\flutter-custom-dialog\example" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" export "FLUTTER_TARGET=lib\main.dart" export "FLUTTER_BUILD_DIR=build" -export "SYMROOT=${SOURCE_ROOT}/../build\ios" -export "FLUTTER_FRAMEWORK_DIR=C:\FlutterSDK\flutter\bin\cache\artifacts\engine\ios" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=false" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.packages" diff --git a/example/lib/dialog/alert_dialog.dart b/example/lib/dialog/alert_dialog.dart index 7498e90..7794e45 100644 --- a/example/lib/dialog/alert_dialog.dart +++ b/example/lib/dialog/alert_dialog.dart @@ -484,3 +484,42 @@ YYDialog YYAlertDialogCustomXY() { ) ..show(80.0, 100.0); } + +YYDialog YYNoticeDialogCallback() { + return YYDialog().build() + ..width = 120 + ..height = 110 + ..backgroundColor = Colors.black.withOpacity(0.8) + ..borderRadius = 10.0 + ..showCallBack = () { + print("showCallBack invoke"); + } + ..dismissCallBack = () { + print("dismissCallBack invoke"); + } + ..widget(Padding( + padding: EdgeInsets.only(top: 21), + child: Image.asset( + 'images/success.png', + width: 38, + height: 38, + ), + )) + ..widget(Padding( + padding: EdgeInsets.only(top: 10), + child: Text( + "Success", + style: TextStyle( + fontSize: 15, + color: Colors.white, + ), + ), + )) + ..animatedFunc = (child, animation) { + return ScaleTransition( + child: child, + scale: Tween(begin: 0.0, end: 1.0).animate(animation), + ); + } + ..show(); +} diff --git a/example/lib/dialog/develop_dialog.dart b/example/lib/dialog/develop_dialog.dart new file mode 100644 index 0000000..16e8898 --- /dev/null +++ b/example/lib/dialog/develop_dialog.dart @@ -0,0 +1,18 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_custom_dialog/flutter_custom_dialog.dart'; + +YYDialog YYFixTextFieldDialog() { + return YYDialog().build() + ..width = 120 + ..height = 110 + ..backgroundColor = Colors.white + ..borderRadius = 10.0 + ..gravity = Gravity.bottom + ..widget( + Padding( + padding: EdgeInsets.all(24), + child: TextField(), + ), + ) + ..show(); +} diff --git a/example/lib/dialog/listview_dialog.dart b/example/lib/dialog/listview_dialog.dart index d2f242c..1f5037f 100644 --- a/example/lib/dialog/listview_dialog.dart +++ b/example/lib/dialog/listview_dialog.dart @@ -151,6 +151,8 @@ YYDialog YYListViewDialogListRadio() { ..listViewOfRadioButton( items: radioItems, height: 370, + intialValue: 2, + color: Colors.white, activeColor: Colors.deepPurpleAccent, onClickItemListener: (index) { var radioItem = radioItems[index]; diff --git a/example/lib/dialog/notice_dialog.dart b/example/lib/dialog/notice_dialog.dart index b34104c..21931da 100644 --- a/example/lib/dialog/notice_dialog.dart +++ b/example/lib/dialog/notice_dialog.dart @@ -25,5 +25,11 @@ YYDialog YYNoticeDialog() { ), ), )) + ..animatedFunc = (child, animation) { + return ScaleTransition( + child: child, + scale: Tween(begin: 0.0, end: 1.0).animate(animation), + ); + } ..show(); } diff --git a/example/lib/main.dart b/example/lib/main.dart index c1ced12..2d7693f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -8,6 +8,8 @@ import 'package:flutter_custom_dialog_example/dialog/progress_dialog.dart'; import 'package:flutter_custom_dialog_example/dialog/notice_dialog.dart'; import 'package:flutter_custom_dialog/flutter_custom_dialog.dart'; +import 'dialog/develop_dialog.dart'; + void main() => runApp(MyApp()); var titleTextStyle = TextStyle(fontSize: 22, color: Colors.black); @@ -72,7 +74,7 @@ showAlertDialog(BuildContext context) { ), Row( children: [ - makeTextButton("bottomsheet", () { + makeTextButton("bottom\nsheet", () { YYBottomSheetDialog(); }), makeTextButton("progress", () { @@ -94,6 +96,9 @@ showAlertDialog(BuildContext context) { makeTextButton("notice", () { YYNoticeDialog(); }), + makeTextButton("callback", () { + YYNoticeDialogCallback(); + }), ], ), Text("2、dialog property"), @@ -198,6 +203,12 @@ showAlertDialog(BuildContext context) { doubleButtonGravity: Gravity.center, ); }), + makeTextButton("space\nEvenly", () { + YYAlertDialogWithGravity( + width: 250.0, + doubleButtonGravity: Gravity.spaceEvenly, + ); + }), ], ), Text("5、dialog animation"), @@ -234,7 +245,7 @@ showDevelopDialog(BuildContext context) { Text("1、debug"), Row( children: [ - makeTextButton("fix dismiss\nbug in v1.0.1", () { + makeTextButton("fix dismiss\nbug", () { Navigator.push( context, MaterialPageRoute( @@ -255,6 +266,9 @@ showDevelopDialog(BuildContext context) { )), ); }), + makeTextButton("fix textfield", () { + YYFixTextFieldDialog(); + }), ], ), ], @@ -264,7 +278,7 @@ showDevelopDialog(BuildContext context) { Widget makeTextButton(title, Function() function) { return SizedBox( - width: 70.0, + width: 65.0, height: 35.0, child: RaisedButton( padding: EdgeInsets.all(0.0), diff --git a/example/pubspec.lock b/example/pubspec.lock index 18bd9d1..0197b10 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,35 +7,56 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.8.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.3.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "0.1.2" + version: "0.1.3" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -47,7 +68,7 @@ packages: path: ".." relative: true source: path - version: "1.0.13" + version: "1.1.1" flutter_test: dependency: "direct dev" description: flutter @@ -59,35 +80,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.7.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -99,55 +106,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.4.2" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.10.0" diff --git a/lib/flutter_custom_dialog.dart b/lib/flutter_custom_dialog.dart index 4339440..63686ca 100644 --- a/lib/flutter_custom_dialog.dart +++ b/lib/flutter_custom_dialog.dart @@ -7,23 +7,33 @@ 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); //弹窗外的背景色 - Color backgroundColor = Colors.white; //弹窗内的背景色 - double borderRadius = 0.0; //弹窗圆角 - 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); //弹窗布局的外边距 - get isShowing => _isShowing; //当前弹窗是否可见 + /// 用于有多个navigator嵌套的情况,默认为true + /// @params useRootNavigator=false,push是用的是当前布局的context + /// @params useRootNavigator=true,push是用的嵌套根布局的context + bool useRootNavigator = true; + + Decoration? decoration; //弹窗内的装饰,与backgroundColor和borderRadius互斥 + Color backgroundColor = Colors.white; //弹窗内的背景色 + double borderRadius = 0.0; //弹窗圆角 + + Function()? showCallBack; //展示的回调 + Function()? dismissCallBack; //消失的回调 + + get isShowing => _isShowing; //当前 弹窗是否可见 bool _isShowing = false; //============================================================================ @@ -31,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; @@ -91,13 +101,15 @@ class YYDialog { fontSize1, fontWeight1, fontFamily1, - VoidCallback onTap1, + VoidCallback? onTap1, + buttonPadding1 = const EdgeInsets.all(0.0), text2, color2, fontSize2, fontWeight2, fontFamily2, onTap2, + buttonPadding2 = const EdgeInsets.all(0.0), }) { return this.widget( SizedBox( @@ -105,44 +117,48 @@ class YYDialog { child: Row( mainAxisAlignment: getRowMainAxisAlignment(gravity), children: [ - FlatButton( + TextButton( onPressed: () { if (onTap1 != null) onTap1(); if (isClickAutoDismiss) { dismiss(); } }, - padding: EdgeInsets.all(0.0), - child: Text( - text1 ?? "", - style: TextStyle( - color: color1 ?? null, - fontSize: fontSize1 ?? null, + style: TextButton.styleFrom( + primary: color1 ?? Colors.black, + padding: buttonPadding1, + textStyle: TextStyle( + fontSize: fontSize1 ?? 18.0, fontWeight: fontWeight1, fontFamily: fontFamily1, - ), + ) + ), + child: Text( + text1 ?? "", ), ), Visibility( visible: withDivider, child: VerticalDivider(), ), - FlatButton( + TextButton( onPressed: () { if (onTap2 != null) onTap2(); if (isClickAutoDismiss) { dismiss(); } }, - padding: EdgeInsets.all(0.0), + style: TextButton.styleFrom( + primary: color2 ?? Colors.black, + padding: buttonPadding2, + textStyle: TextStyle( + fontSize: fontSize2 ?? 14.0, + fontWeight: fontWeight2, + fontFamily: fontFamily2, + ), + ), child: Text( text2 ?? "", - style: TextStyle( - color: color2 ?? Colors.black, - fontSize: fontSize2 ?? 14.0, - fontWeight: fontWeight2, - fontFamily: fontFamily2, - ), ), ) ], @@ -152,10 +168,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( @@ -163,7 +179,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, @@ -177,15 +193,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, ), ), ), @@ -198,12 +214,14 @@ class YYDialog { } YYDialog listViewOfRadioButton({ - List items, - double height, - Color activeColor, - 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, @@ -214,6 +232,8 @@ class YYDialog { ), child: YYRadioListTile( items: items, + intialValue: intialValue, + color: color, activeColor: activeColor, onChanged: onClickItemListener, ), @@ -254,7 +274,7 @@ class YYDialog { CustomDialog( gravity: gravity, gravityAnimationEnable: gravityAnimationEnable, - context: this.context, + context: this.context!, barrierColor: barrierColor, animatedFunc: animatedFunc, barrierDismissible: barrierDismissible, @@ -267,19 +287,27 @@ class YYDialog { crossAxisAlignment: crossAxisAlignment, children: [ Material( + clipBehavior: Clip.antiAlias, type: MaterialType.transparency, + borderRadius: BorderRadius.circular(borderRadius), child: Container( - padding: EdgeInsets.all(borderRadius / 3.14), width: width ?? null, height: height ?? null, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(borderRadius), - color: backgroundColor, - ), + decoration: decoration ?? + BoxDecoration( + borderRadius: BorderRadius.circular(borderRadius), + color: backgroundColor, + ), constraints: constraints ?? BoxConstraints(), child: CustomDialogChildren( widgetList: widgetList, isShowingChange: (bool isShowingChange) { + // showing or dismiss Callback + if (isShowingChange) { + showCallBack?.call(); + } else { + dismissCallBack?.call(); + } _isShowing = isShowingChange; }, ), @@ -293,7 +321,7 @@ class YYDialog { void dismiss() { if (_isShowing) { - Navigator.of(context, rootNavigator: true).pop(); + Navigator.of(context!, rootNavigator: useRootNavigator).pop(); } } @@ -360,6 +388,9 @@ class YYDialog { case Gravity.right: mainAxisAlignment = MainAxisAlignment.end; break; + case Gravity.spaceEvenly: + mainAxisAlignment = MainAxisAlignment.spaceEvenly; + break; case Gravity.center: default: mainAxisAlignment = MainAxisAlignment.center; @@ -371,10 +402,10 @@ class YYDialog { ///弹窗的内容作为可变组件 class CustomDialogChildren extends StatefulWidget { - List widgetList = []; //弹窗内部所有组件 - Function(bool) isShowingChange; + final List widgetList; //弹窗内部所有组件 + final Function(bool)? isShowingChange; - CustomDialogChildren({this.widgetList, this.isShowingChange}); + CustomDialogChildren({this.widgetList = const [], this.isShowingChange}); @override CustomDialogChildState createState() => CustomDialogChildState(); @@ -383,7 +414,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, ); @@ -391,7 +424,9 @@ class CustomDialogChildState extends State { @override void dispose() { - widget.isShowingChange(false); + if (widget.isShowingChange != null) { + widget.isShowingChange!(false); + } super.dispose(); } } @@ -400,24 +435,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, @@ -500,7 +535,7 @@ class CustomDialog { //自定义动画 if (_animatedFunc != null) { - return _animatedFunc(child, animation); + return _animatedFunc!(child, animation); } //不需要默认动画 @@ -529,6 +564,7 @@ enum Gravity { leftTop, rightBottom, leftBottom, + spaceEvenly, } //============================================================================ @@ -544,13 +580,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 { @@ -563,11 +599,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 f90bb87..9114a9d 100644 --- a/lib/flutter_custom_dialog_widget.dart +++ b/lib/flutter_custom_dialog_widget.dart @@ -1,3 +1,5 @@ +import 'dart:ui'; + import 'package:flutter/material.dart'; import 'package:flutter_custom_dialog/flutter_custom_dialog.dart'; @@ -5,16 +7,20 @@ 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, this.activeColor, this.onChanged, }) : assert(items != null), super(key: key); - List items; - Color activeColor; - Function(int) onChanged; + final List? items; + final Color? color; + final Color? activeColor; + final intialValue; + final Function(int)? onChanged; @override State createState() { @@ -23,26 +29,46 @@ class YYRadioListTile extends StatefulWidget { } class YYRadioListTileState extends State { - var groupId = 0; + var groupId = -1; + + void intialSelectedItem() { + //intialValue: + //The button initializes the position. + //If it is not filled, it is not selected. + if (groupId == -1) { + groupId = widget.intialValue ?? -1; + } + } @override Widget build(BuildContext context) { + intialSelectedItem(); + 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: Colors.white, + color: widget.color, child: RadioListTile( - title: Text(widget.items[index].text), + title: Text( + widget.items?[index].text ?? "", + style: TextStyle( + 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/local.properties b/local.properties new file mode 100644 index 0000000..c154f3d --- /dev/null +++ b/local.properties @@ -0,0 +1,8 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration. +# +# Location of the SDK. This is only used by Gradle. +# For customization when using a Version Control System, please read the +# header note. +#Mon Aug 16 16:54:26 CST 2021 +sdk.dir=C\:\\Users\\Administrator\\AppData\\Local\\Android\\Sdk diff --git a/pubspec.lock b/pubspec.lock index aebdafa..4fe6b9f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,28 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.8.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.3.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -45,35 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.7.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -85,55 +92,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.4.2" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.10.0" diff --git a/pubspec.yaml b/pubspec.yaml index d313a44..0f7102b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: flutter_custom_dialog -description: Semantic dialog -version: 1.0.14 -author: AndroidHensen +description: Semantic dialog | Made In YY.inc | Welcome to contribute +version: 1.3.0 homepage: https://github.com/YYFlutter/flutter-custom-dialog.git environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" + flutter: ">=1.10.0" dependencies: flutter: @@ -25,8 +25,12 @@ flutter: # be modified. They are used by the tooling to maintain consistency when # adding or updating assets for this project. plugin: - androidPackage: yy.inc.flutter_custom_dialog - pluginClass: FlutterCustomDialogPlugin + platforms: + android: + package: yy.inc.flutter_custom_dialog + pluginClass: FlutterCustomDialogPlugin + ios: + pluginClass: FlutterCustomDialogPlugin # To add assets to your plugin package, add an assets section, like this: # assets: