我还是新来的颤栗。当单击对话框外部时,我尝试使我的对话框能够被关闭。然而,如果我使用Scaffold,障碍--:true--不起作用。我试着使用Wrap,但是有一个错误:没有找到任何物质小部件。对如何取消对话有任何想法吗?
这是我的密码:
showGeneralDialog(
barrierDismissible: true,
pageBuilder: (context, anim1, anim2) {
context1 = context;
return StatefulBuilder(
builder: (context, setState) {
return Scaffold(
backgroundColor: Colors.black .withOpacity(0.0),
body: Align(
alignment: Alignment.bottomCenter,
child: Container(
child: InkWell()
)
)
}
}
)发布于 2020-12-03 18:29:20
脚手架不需要显示showGeneralDialog。在您的代码中需要材料小部件,因为InkWell小部件需要一个物质祖先。您可以使用任何提供材料的小部件,如Card或material本身。此外,barrierLabel不能为空。
请查看下面的工作代码,否则您可以直接在达特帕德 https://dartpad.dev/6c047a6cabec9bbd00a048c972098671上运行该代码。
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text("showGeneralDialog Demo"),
),
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: () {
showGeneralDialog(
context: context,
barrierDismissible: true,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
barrierColor: Colors.black54,
pageBuilder: (context, anim1, anim2) {
return Center(
child: Container(
width: 200,
height: 100,
child: StatefulBuilder(
builder: (context, snapshot) {
return const Card(
color: Colors.white,
child: Center(
child: InkWell(
child: Text(
"Press outside to close",
style: TextStyle(color: Colors.black),
),
),
),
);
},
),
),
);
},
);
},
child: const Text("Show Dialog"));
}
}发布于 2022-03-27 13:51:29
对于任何需要在AlertDialogs中使用Scaffold的人(也许是使用ScaffoldMessenger),以下是简单的工作:
用IgnorePointer包脚手架。"barrierDismissible“值现在可以工作了。
@override
Widget build(BuildContext context) {
return IgnorePointer(
child: Scaffold(
backgroundColor: Colors.transparent,
body: AlertDialog(
title: title,
content: SizedBox(
width: MediaQuery.of(context).size.width,
child: SingleChildScrollView(
child: ListBody(
children: content
),
),
),
actions: actions,
insetPadding: const EdgeInsets.all(24.0),
shape: Theme.of(context).dialogTheme.shape,
backgroundColor: Theme.of(context).dialogTheme.backgroundColor,
)
),
);
}发布于 2022-06-15 05:55:54
将此添加到showGeneralDialog中
barrierLabel: "" 代码将如下所示
showGeneralDialog(
barrierDismissible: true,
barrierLabel: "",
pageBuilder: (context, anim1, anim2) {
context1 = context;
return StatefulBuilder(
builder: (context, setState) {
return Scaffold(
backgroundColor: Colors.black .withOpacity(0.0),
body: Align(
alignment: Alignment.bottomCenter,
child: Container(
child: InkWell()
)
)
}
}
)https://stackoverflow.com/questions/65130492
复制相似问题