skip to Main Content

When you click on the button to show awesome dialog, transparency appears over the application screen, but awesome dialog does not appear

  void askDoAgain() {
    AwesomeDialog(
      context: context,
      headerAnimationLoop: false,
      dialogType: DialogType.question,
      animType: AnimType.topSlide,
      title: trans(context, 'make_another_transaction'),
      desc: trans(context, 'start_new_transaction'),
      btnCancelText: trans(context, 'cancel'),
      btnOkText: trans(context, 'ok'),
      btnCancelOnPress: () {
        // Navigator.pop(context);
      },
      btnCancelColor: Colors.grey[600],
      btnOkColor: colors.primaryColor,
      btnOkOnPress: () async {
        customerName.clear();
        customerPhone.clear();
        customerLocation.clear();
        _btnController.reset();
      },
    ).show();
  }

function: () {
askDoAgain();

        }

2

Answers


  1. i think using the wrong context which show the AwesomeDialog.Make sure you have access to the correct context within the scope of the function askDoAgain().i modified your code just check it

    void askDoAgain(BuildContext context) { // Add the 'BuildContext' parameter
      AwesomeDialog(
        context: context,
        headerAnimationLoop: false,
        dialogType: DialogType.question,
        animType: AnimType.topSlide,
        title: trans(context, 'make_another_transaction'),
        desc: trans(context, 'start_new_transaction'),
        btnCancelText: trans(context, 'cancel'),
        btnOkText: trans(context, 'ok'),
        btnCancelOnPress: () {
          Navigator.pop(context); // You can uncomment this line if needed
        },
        btnCancelColor: Colors.grey[600],
        btnOkColor: colors.primaryColor,
        btnOkOnPress: () async {
          customerName.clear();
          customerPhone.clear();
          customerLocation.clear();
          _btnController.reset();
          Navigator.pop(context); // Close the dialog after successful action
        },
      ).show();
    }
    //Then, make sure you're calling the askDoAgain() function with the correct context when you want to show the AwesomeDialog
        FlatButton(
      onPressed: () {
        askDoAgain(context); // Pass the context to the function
      },
      child: Text('Show Dialog'),
    ),
    
    Login or Signup to reply.
  2. The following code seems to work for me, I had to comment some of your code because I was missing the functions/classes:

    import 'package:awesome_dialog/awesome_dialog.dart';
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: MyPage(),
        );
      }
    }
    
    class MyPage extends StatelessWidget {
      const MyPage({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: ElevatedButton(
              onPressed: () => AwesomeDialog(
                context: context,
                headerAnimationLoop: false,
                dialogType: DialogType.question,
                animType: AnimType.topSlide,
                // title: trans(context, 'make_another_transaction'),
                // desc: trans(context, 'start_new_transaction'),
                // btnCancelText: trans(context, 'cancel'),
                // btnOkText: trans(context, 'ok'),
                btnCancelOnPress: () {
                  // Navigator.pop(context);
                },
                btnCancelColor: Colors.grey[600],
                // btnOkColor: colors.primaryColor,
                btnOkOnPress: () async {
                  // customerName.clear();
                  // customerPhone.clear();
                  // customerLocation.clear();
                  // _btnController.reset();
                },
              ).show(),
              child: Text('Awesome Dialog'),
            ),
          ),
        );
      }
    }
    

    What I think what was going wrong is that you were not providing the right context. Whenever you want to display a Dialog you need to make sure that the provided context is from a Material widget. In the case of this example, I am providing the context from the Scaffold widget which is a Material widget.

    awesome dialog example

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search