Home > OS >  Flutter The type parameter is not nullable: null
Flutter The type parameter is not nullable: null

Time:06-08

On the line await Future<int>.delayed(Duration(seconds: 3)); the error The type parameter is not nullable: null is thrown.

Future<dynamic> createSomething() async {
  showDialog(
    context: context,
    builder: (BuildContext context) => Center(
      child: CircularProgressIndicator(),
    ),
  );
  await Future<int>.delayed(Duration(seconds: 3));

  Navigator.of(context, rootNavigator: true).pop();
}

Widget build(BuildContext context) {
  return TextButton(
    onPressed: () {
      createSomething();
    },
    child: const Text('Show Dialog'),
  );
}

CodePudding user response:

The return type of the function is dynamic and you don't return anything, Declare the type of the function as Future<void>

also write Future.delayed not Future<int>.delayed as this future also returns nothing.

CodePudding user response:

remove <int> i think it's worked or use <dynamic> like this

await Future<dynamic>.delayed(Duration(seconds: 3));

or like that

await Future.delayed(Duration(seconds: 3));
  • Related