Why using <Null> after showDialog?


Asked by NOOBIT on November 14, 2021 (source).

Here I'm rendering an AlertDialog inside showDialog to display when error thrown from provider file. But that didn't work first time( Seems like stuck in catchError block, didn't execute future of catchError), Then I told to add <Null> after showDialog. That worked But How, What is changed, what it means?

Here is the code

if (_editedProduct.id == null) {
    Provider.of<Products>(context, listen: false)
        .catchError((error) {
      return showDialog<Null>(     //Here is that Null I didn't understand
          context: context,
          builder: (ctx) {
            return AlertDialog(
              title: Text('ERROR'),
              content: Text('Error Occured'),
              actions: [
                  onPressed: () {
                  child: Text('I GOT IT'),
    }).then((_) {
      setState(() {
        isLoading = false;
  } else {
    Provider.of<Products>(context, listen: false)
        .updateProduct(_editedProduct.id, _editedProduct);

Nb: isLoading true shows a circluarProgressIndicator()


Question answered by Wilfred A (source).

From the Official Docs

Returns a Future that resolves to the value (if any) that was passed to Navigator.pop when the dialog was closed.

The place where you sent Null indicates the type of data the Future will return.

By using Null you are indicating that the Future won't return any data, this tell your program not to wait for the possible value that might be returned.

Suppose in your dialog user has to pick 2 numbers and you want the picked number to be returned to the place where you called the showDialog() function then you'll use int instead of Null.

Something like