英文:
show alert dialog in flutter without onTap, onPressed etc
问题
如何在Flutter中无需用户交互显示警报对话框?
我有一个小部件,显示一个ListView
。当特定条件为真时,我想在同一个小部件内显示一个警报对话框(在Flutter中一切都是小部件,对吗?)。因此,不需要用户交互。
这是我的小部件的构建方法:
@override
Widget build(BuildContext context, WidgetRef ref) {
final providerData = ref.watch(someProvider);
//showAlertDialog(context);
final anotherProviderData = ref.watch(anotherProvider);
return anotherProviderData.when(
data: (entries) {
return CustomScrollView(...
我想基于提供者数据显示一个AlertDialog
。
英文:
How do I display an alert dialog in flutter without user interaction?
I have a Widget that shows a ListView
. When a specific condition is true, I want to display an alert dialog within the same widget (everything is a widget in Flutter, right?). So no user interaction is needed.
this is the build method of my widget:
@override
Widget build(BuildContext context, WidgetRef ref) {
final providerData = ref.watch(someProvider);
//showAlertDialog(context);
final anotherProviderData = ref.watch(anotherProvider);
return anotherProviderData.when(
data: (entries) {
return CustomScrollView(...
I want to display an AlertDialog
based upon the provider data.
答案1
得分: 1
你可以从根据你的触发调用的函数中调用 showDialog
。
showDialog(
context: context,
builder: (BuildContext context) {
return MyAlertDialog();
});
英文:
You can call showDialog
from a function you call based upon your trigger.
showDialog(
context: context,
builder: (BuildContext context) {
return MyAlertDialog();
});
答案2
得分: 0
我弄清楚如何做了:
Future(() {
showAlertDialog(context);
});
showAlertDialog(context)
是显示警报对话框的方法。
英文:
I figured out how to do it:
Future(() {
showAlertDialog(context);
});
showAlertDialog(context)
is the method showing the alert dialog.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论