Flutter 的Dialog使用

  1. Flutter Dialog
    (1)AboutDialog
    Flutter 的Dialog使用_第1张图片
    (2)AlertDialog
    Flutter 的Dialog使用_第2张图片
    (3)SimpleDialog
    Flutter 的Dialog使用_第3张图片

// AboutDialog
  void showAboutDialog(BuildContext context) {
    showDialog(context: context, builder: (_) => new AboutDialog(
      applicationName: 'AndroidStudio',
      applicationIcon: Icon(Icons.add_chart),
      children: [
        Text('这是一个AndroidStudio')
      ],
    ));
  }

  // SimpleDialog
  void showSimpleDialog(BuildContext context) {
    showDialog(context: context, builder: (_) => new SimpleDialog(
      title: Text('选择'),
      children: [
        SimpleDialogOption(
          child: Text('选项1'),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
        SimpleDialogOption(
          child: Text('选项2'),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
        SimpleDialogOption(
          child: Text('选项3'),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
        SimpleDialogOption(
          child: Text('选项4'),
          onPressed: () {
            Navigator.of(context).pop();
          },
        )
      ],
    ));
  }

  // AlertDialog
  void showAlertDialog(BuildContext context) {
    showDialog(context: context, builder: (_) => new AlertDialog(
      title: Text('标题'),
      content: SingleChildScrollView(
        child: ListBody(
          children: [
            Text('较长的List。。。'),
            Text('较长的List。。。'),
            Text('较长的List。。。'),
            Text('较长的List。。。'),
            Text('较长的List。。。'),
            Text('较长的List。。。'),
            Text('较长的List。。。'),
            Text('较长的List。。。'),
            Text('较长的List。。。'),
          ],
        ),
      ),
      actions: [
        FlatButton(onPressed: () {
          Navigator.of(context).pop();
        }, child: Text('确定')),
        FlatButton(onPressed: () {
          Navigator.of(context).pop();
        }, child: Text('取消')),
      ],
    ));
  }

你可能感兴趣的:(flutter)