对全局弹窗的功能封装,用语义化的方式对弹窗内部的内容进行填充,目前提供的功能git
一、installgithub
dependencies:
flutter_custom_dialog: ^1.0.4
复制代码
二、import网络
import 'package:flutter_custom_dialog/flutter_custom_dialog.dart';
复制代码
dialog_demoapp
![]() divider ✅ |
![]() body ✅ |
![]() head&body ✅ |
![]() listTile ✅ |
![]() ListRadio ✅ |
![]() progress ✅ |
![]() progress&body ✅ |
![]() pop menu ✅ 支持自定义位置 |
dialog_gravityless
![]() bottom ✅ |
![]() top ✅ |
![]() left ✅ |
![]() right ✅ |
![]() center ✅ |
![]() left bottom ✅ |
![]() left top ✅ |
![]() right bottom ✅ |
![]() right top ✅ |
dialog_animationide
![]() scaleIn ✅ |
![]() fadeIn ✅ |
![]() rotateIn ✅ |
![]() customIn ✅ 支持自定义动画 |
弹窗的属性设置能够经过成员变量的方法去调用,具体详见下表svg
YYDialog YYDialogDemo(BuildContext context) {
return YYDialog().build(context)
..width = 220
..height = 500
..barrierColor = Colors.black.withOpacity(.3)
..animatedFunc = (child, animation) {
return ScaleTransition(
child: child,
scale: Tween(begin: 0.0, end: 1.0).animate(animation),
);
}
..borderRadius = 4.0
..show();
}
复制代码
支持的属性函数
property | description | default |
---|---|---|
width | 弹窗宽度 | 0 |
height | 弹窗高度 | 自适应组件高度 |
duration | 弹窗动画出现的时间 | 250毫秒 |
gravity | 弹窗出现的位置 | 居中 |
gravityAnimationEnable | 弹窗出现的位置带有的默认动画是否可用 | false |
margin | 弹窗的外边距 | EdgeInsets.all(0.0) |
barrierColor | 弹窗外的背景色 | 30%黑色 |
backgroundColor | 弹窗内的背景色 | 白色 |
borderRadius | 弹窗圆角 | 0.0 |
constraints | 弹窗约束 | 最小宽高不低于10% |
animatedFunc | 弹窗出现的动画 | 从中间出现 |
barrierDismissible | 是否点击弹出外部消失 | true |
支持的方法动画
method | description |
---|---|
show[x,y] | 显示弹窗 |
dismiss | 隐藏弹窗 |
isShowing | 弹窗是否在展现 |
弹窗内部的组件内容提早经过语义化的函数封装好经常使用的组件,以便快速构建出弹窗,具体见下表ui
YYDialog YYAlertDialogWithDivider(BuildContext context) {
return YYDialog().build(context)
..width = 220
..borderRadius = 4.0
..text(
padding: EdgeInsets.all(25.0),
alignment: Alignment.center,
text: "肯定要退出登陆吗?",
color: Colors.black,
fontSize: 14.0,
fontWeight: FontWeight.w500,
)
..divider()
..doubleButton(
padding: EdgeInsets.only(top: 10.0),
gravity: Gravity.center,
withDivider: true,
text1: "取消",
color1: Colors.redAccent,
fontSize1: 14.0,
fontWeight1: FontWeight.bold,
onTap1: () {
print("取消");
},
text2: "肯定",
color2: Colors.redAccent,
fontSize2: 14.0,
fontWeight2: FontWeight.bold,
onTap2: () {
print("肯定");
},
)
..show();
}
复制代码
支持的语义化组件
method | description |
---|---|
text | 文本控件 |
doubleButton | 双按钮控件 |
listViewOfListTile | 列表Tile组件 |
listViewOfRadioButton | 列表按钮组件 |
divider | 分割线组件 |
widget | 自定义语义化组件 |
自定义弹窗内部组件内容
经过
widget()
将组件插入弹窗
YYDialog YYDialogDemo(BuildContext context) {
return YYDialog().build(context)
..width = 220
..height = 500
..widget(
Padding(
padding: EdgeInsets.all(0.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"",
style: TextStyle(
color: Colors.black,
fontSize: 14.0,
fontWeight: FontWeight.w100,
),
),
),
),
)
..show();
}
复制代码
一、init
在未弹窗以前先调用静态方法YYDialog.init(context);
class AppHome extends StatelessWidget {
Widget build(BuildContext context) {
//一、初始化context
YYDialog.init(context);
//二、后续使用能够不须要context
......
}
}
复制代码
二、use
直接使用YYDialog
,注意必需要调用build()
YYDialog YYAlertDialogBody() {
return YYDialog().build()
..width = 240
..text(
text: "Hello YYDialog",
color: Colors.grey[700],
)
..show();
}
复制代码
Apache License 2.0