是否有 way/workaround 可以在 Flutter 的模糊对话框顶部显示一个快餐栏?
Is there a way/workaround to show a snackbar on top of the blurred dialog with Flutter?
下面是当前situation/problem的截图。我有一个背景模糊的对话框。我想在用户单击“复制推荐 link”按钮时显示一个快餐栏。但是,由于我在对话框上放置了模糊的背景,所以 snackbar 也保留在背景后面。
我想要的是在用户单击按钮时不模糊地显示快餐栏。我怎样才能达到这个结果?背景应该总是模糊的,但我只需要在用户单击按钮时在模糊的顶部显示小吃栏。
Here's the image url that shows the current problem
您可以通过创建自定义对话框来打开对话框,就像我下面的代码
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool isShow = false;
void _incrementCounter() {
setState(() {
isShow = !isShow;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Stack(
children: [
ConstrainedBox(
constraints: const BoxConstraints.expand(),
child: const FlutterLogo(),
),
isShow
? GestureDetector(
onTap: _incrementCounter,
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
color: Colors.black38,
alignment: Alignment.center,
child: GestureDetector(
onTap: () {},
child: AlertDialog(
content: const Text("dsd"),
actions: [
ElevatedButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Awesome Snackbar!'),
action: SnackBarAction(
label: 'Action',
onPressed: () {
// Code to execute.
},
),
),
);
},
child: const Text("Show Snackbar"),
)
],
),
),
),
)
: const SizedBox()
],
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.notifications),
),
);
}
}
截图:https://i.stack.imgur.com/inX4I.png
由于缺少信誉点,我无法显示图像
下面是当前situation/problem的截图。我有一个背景模糊的对话框。我想在用户单击“复制推荐 link”按钮时显示一个快餐栏。但是,由于我在对话框上放置了模糊的背景,所以 snackbar 也保留在背景后面。
我想要的是在用户单击按钮时不模糊地显示快餐栏。我怎样才能达到这个结果?背景应该总是模糊的,但我只需要在用户单击按钮时在模糊的顶部显示小吃栏。
Here's the image url that shows the current problem
您可以通过创建自定义对话框来打开对话框,就像我下面的代码
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool isShow = false;
void _incrementCounter() {
setState(() {
isShow = !isShow;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Stack(
children: [
ConstrainedBox(
constraints: const BoxConstraints.expand(),
child: const FlutterLogo(),
),
isShow
? GestureDetector(
onTap: _incrementCounter,
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
color: Colors.black38,
alignment: Alignment.center,
child: GestureDetector(
onTap: () {},
child: AlertDialog(
content: const Text("dsd"),
actions: [
ElevatedButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Awesome Snackbar!'),
action: SnackBarAction(
label: 'Action',
onPressed: () {
// Code to execute.
},
),
),
);
},
child: const Text("Show Snackbar"),
)
],
),
),
),
)
: const SizedBox()
],
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.notifications),
),
);
}
}
截图:https://i.stack.imgur.com/inX4I.png
由于缺少信誉点,我无法显示图像