flutter 弹窗
flutter 弹窗
2023-09-14 09:04:29 时间
参考
AlertDialog
new MaterialButton(
color: Colors.blue,
child: new Text('点我'),
onPressed: () {
showDialog<Null>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return new AlertDialog(
title: new Text('标题'),
content: new SingleChildScrollView(
child: new ListBody(
children: <Widget>[
new Text('内容 1'),
new Text('内容 2'),
],
),
),
actions: <Widget>[
new FlatButton(
child: new Text('确定'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
).then((val) {
print(val);
});
},
),
SimpleDialog
new MaterialButton(
color: Colors.blue,
child: new Text('点我'),
onPressed: () {
showDialog<Null>(
context: context,
builder: (BuildContext context) {
return new SimpleDialog(
title: new Text('选择'),
children: <Widget>[
new SimpleDialogOption(
child: new Text('选项 1'),
onPressed: () {
Navigator.of(context).pop();
},
),
new SimpleDialogOption(
child: new Text('选项 2'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
).then((val) {
print(val);
});
},
),
这个是我代码里面的
Container(
margin: const EdgeInsets.only(left: 40.0, right: 40.0),
child: ElevatedButton(
onPressed: () {
showDialog<Null>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('标题'),
content: SingleChildScrollView(
child: ListBody(
children: const <Widget>[
Text('确定关注该歌手吗'),
Text('内容 2'),
],
),
),
actions: <Widget>[
FlatButton(
child: const Text('确定'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
).then((val) {
print(val);
});
},
child: const Text("+ 关注"),
),
),
相关文章
- flutter源码:布局
- Flutter 下载器 | flutter_download_manager源码解析
- flutter系列之:如丝般顺滑的SliverAppBar
- Flutter Web - 一种取巧的 CDN 方案
- 第127期:Flutter的Text组件
- Flutter 组件集录 | 3.7 新增 - ContextMenu 菜单
- 【错误记录】Flutter 设备连接显示 Loading... ( 断网 | 删除 flutter/bin/cache/lockfile 文件 )
- 【Flutter】Flutter 打开第三方应用 ( url_launcher 插件搜索与安装 | url_launcher 插件官方示例 | 打开浏览器 | 打开第三方应用 )
- 【Flutter】打开第三方 Flutter 项目
- 【错误记录】Flutter 报错 ( Because xx depends on flutter_driver any from sdk which depends on args 1.6.0 )
- 【Flutter】顶部导航栏实现 ( Scaffold | DefaultTabController | TabBar | Tab | TabBarView )
- Flutter 后台任务