skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    I figured out how to do it:

    Future(() {
            showAlertDialog(context);
          });
    

    showAlertDialog(context) is the method showing the alert dialog.


  2. You can call showDialog from a function you call based upon your trigger.

    showDialog(
        context: context,
        builder: (BuildContext context) {
          return MyAlertDialog();
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search