skip to Main Content

[enter image description here](https://i.stack.imgur.com/uTSBa.png)

I have created a Dialog Widgets. It will show the Error when i write AlertDialog.adaptive. withour adaptive Widgets No erorr. Is anyone know how to fix this error.

Is anyone know how to fix this error.

2

Answers


  1. First of all you need to update your flutter version to 3.13 or higher version, because AlertDialog.adaptive feature came with 3.13.
    The 3.13 framework improvement – https://medium.com/@ak187429/flutter-3-13-framework-improvements-41be37e925d8.
    On the writing, the writer mentions abaout AlertDialog.adaptive.
    There is example code for AlertDialog.adaptive

    floatingActionButton: FloatingActionButton.extended(
            label: const Text('Show Alert Dialog Adaptive'),
            onPressed: () async {
              final response = await showAdaptiveDialog<bool>(
                context: context,
                builder: (context) {
                  return AlertDialog.adaptive(
                    content: const Text('This is an adaptive alert dialog'),
                    actions: [
                      TextButton(
                        onPressed: () => Navigator.of(context).pop(false),
                        child: const Text('Cancel'),
                      ),
                      TextButton(
                        onPressed: () => Navigator.of(context).pop(true),
                        child: const Text('OK'),
                      ),
                    ],
                  );
                },
              );
              print(response);
            },
          ),
    

    My flutter version – 3.13.8,
    My dart version – 3.1.4,
    This code works on my computer 🙂

    Login or Signup to reply.
  2. I run your Code what i Did i declare a function showDialoog here is the code
    and the result is in ScreenShot its working fine
    Result

    showDialoog(BuildContext context)async{
    final endExam = await showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog.adaptive(
          title: const Text("Submit Exam"),
          content: Text(
            'You have time left.n'
            'Are you sure you want to submit?',
          ),
          actions: [
            TextButton(
              onPressed: () {
                Navigator.pop(context, false);
              },
              child: const Text("Cancel"),
            ),
            TextButton(
              onPressed: () {
                Navigator.pop(context, true);
              },
              child: const Text(
                "Submit",
                style: TextStyle(color: Colors.red),
              ),
            ),
          ],
        );
      },
    );
    }```
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search