1

I have this dialog But when I call it it gives me this error : Unhandled Exception: 'package:flutter/src/widgets/localizations.dart': Failed assertion: line 453 pos 12: 'context != null': is not true., My Code:

return showDialog(
      context: context,
      child: AlertDialog(
        title: Text(title),
        content: Text(msg),
        actions: [cancel, ok],
      ),
    );
nvoigt
  • 75,013
  • 26
  • 93
  • 142
OKKO
  • 33
  • 8

1 Answers1

1

The error message tells you exactly what's wrong: your variable context is null.

You need to provide a context that is not null.

You should also provide builder instead of a child, because that way to build a dialog is deprecated for good reason.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • I tried to add builder but ut is the same, about context should I define it outside the function ? – OKKO Aug 11 '20 at 07:23
  • You should pass a valid context. Since I don't know anything about what you actually did or what your code looks like, it's hard to say. Please edit your question to contain a [mcve], not just a snippet. – nvoigt Aug 11 '20 at 07:25