showDialog基本属性

  1. Future<T> showDialog<T>({
  2. @required BuildContext context, // 在当前应用程序内容上方显示一个材质对话框,包含材质入口和退出动画、
  3. bool barrierDismissible = true,
  4. @Deprecated(
  5. 'Instead of using the "child" argument, return the child from a closure '
  6. 'provided to the "builder" argument. This will ensure that the BuildContext '
  7. 'is appropriate for widgets built in the dialog. '
  8. 'This feature was deprecated after v0.2.3.'
  9. )
  10. Widget child, // 用不是,用了会出现崩溃效果
  11. WidgetBuilder builder, // 不能和child共存
  12. bool useRootNavigator = true, // AlertDialog
  13. RouteSettings routeSettings,
  14. })
  • 一般我们使用context 和 builder就行了。

showDialog基本用法

  1. showDialog(
  2. context: context,
  3. builder: (context) {
  4. return Text('333')
  5. }
  6. );

image.png

  • 这样的弹框太丑陋了,所以需要用到下面的弹框提示,只是用showDialog做一个跳板。

    AlertDialog 提示框(Material风格)

  • 当应用程序进行重要操作时,经常需要用户进行2次确认,以免避免用户的误操作。

AlertDialog基本属性

  1. const AlertDialog({
  2. Key key,
  3. this.title,
  4. this.titlePadding,
  5. this.titleTextStyle,
  6. this.content,
  7. this.contentPadding = const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
  8. this.contentTextStyle,
  9. this.actions,
  10. this.actionsPadding = EdgeInsets.zero,
  11. this.actionsOverflowDirection,
  12. this.actionsOverflowButtonSpacing,
  13. this.buttonPadding,
  14. this.backgroundColor,
  15. this.elevation,
  16. this.semanticLabel,
  17. this.insetPadding = _defaultInsetPadding,
  18. this.clipBehavior = Clip.none,
  19. this.shape,
  20. this.scrollable = false,
  21. }) : assert(contentPadding != null),
  22. assert(clipBehavior != null),
  23. super(key: key);
  • 属性中都是见名知意的就不多说了

image.png

CupertinoAlertDialog 提示框(Cupertino ios风格)

  1. showDialog(
  2. context: context,
  3. builder: (context) {
  4. return CupertinoAlertDialog(
  5. title: Text('温馨提示'),
  6. content: Text(title),
  7. actions: <Widget>[
  8. FlatButton(child: Text('取消'),onPressed: (){
  9. Navigator.of(context).pop('no');
  10. },),
  11. FlatButton(child: Text('确认'),onPressed: (){
  12. Navigator.of(context).pop('ok');
  13. },),
  14. ],
  15. );
  16. }
  17. );

image.png