Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The argument type 'Widget?' can't be assigned to the parameter type 'Widget'

Tags:

flutter

dart

I wrap the app in a scrollconfiguration to remove the scrollglow. This always worked but it has been quite a time since i used flutter so i created a new project but it gives this error.

ProviderScope(
      child: MaterialApp(
        title: 'testing',
        themeMode: ThemeMode.light,
        darkTheme: darkTheme(),
        theme: lightTheme(),
        onGenerateRoute: RouteGenerator.generateRoute,
        initialRoute: '/',
        builder: (context, child) {
          return ScrollConfiguration(
            behavior: RemoveScrollGlow(),
            child: child,
          );
        },
      )
    )

The probleme is child: child. I have no idea how to fix this.

class RemoveScrollGlow extends ScrollBehavior {
  @override
  Widget buildOverscrollIndicator(
    BuildContext context, Widget child, ScrollableDetails details) {
    return child;
  }
}
like image 232
ARVOCI Avatar asked May 19 '21 07:05

ARVOCI


Video Answer


2 Answers

If you are sure the value will never be null, you can cast it to the non-nullable type, ie. Widget explicitly. Or simply add an ! suffix, like this: child!.

like image 78
Riwen Avatar answered Oct 10 '22 06:10

Riwen


You would have updated the dart SDK version and hence null safety is included in your project.

It's pretty simple to solve just go to your pubspec.yaml file and under environment variable, you will find the dart SDK range which should be something like this sdk: ">=2.12.0 <3.0.0".

Now you just have to change it from 2.12.0 to 2.7.0 which will enable your project to run without null safety and will make your project error-free. So the updated sdk version should look like sdk: ">=2.7.0 <3.0.0".

Hope it will help you.

like image 34
VIREN GAJJAR Avatar answered Oct 10 '22 06:10

VIREN GAJJAR