Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix this nullOk error when using the flutter_svg package?

Tags:

flutter

dart

I connected the package, added it to main.dart, I try to compile the application, but I get this error. Help! What should I do about it?

error

Launching lib\main.dart on XT1562 in debug mode...
Running Gradle task 'assembleDebug'...
/D:/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_svg-0.18.1/lib/src/picture_provider.dart:50:59: Error: No named parameter with the name 'nullOk'.
        context != null ? Localizations.localeOf(context, nullOk: true) : null,
                                                          ^^^^^^
/D:/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't match.
  static Locale localeOf(BuildContext context) {
                ^^^^^^^^


FAILURE: Build failed with an exception.

* Where:
Script 'D:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 15s
Exception: Gradle task assembleDebug failed with exit code 1
like image 643
Ctrixago Avatar asked Feb 10 '21 20:02

Ctrixago


2 Answers

Follow the steps below

  1. add the following dependency
  flutter_svg: ^0.20.0-nullsafety.3
  1. run flutter clean command
  2. run flutter pub get command
  3. run flutter run command or run the project
like image 71
prahack Avatar answered Nov 17 '22 13:11

prahack


Everyone is right: putting flutter_svg: ^0.20.0-nullsafety.3 or flutter_svg: ^0.19.3 (in case you can't migrate to null safety yet) is the solution. I want to add a little thing: if you're using a package which depends on flutter_svg and you still get the error due to older versions usage, you can fix it in this way:

dependency_overrides:
  flutter_svg: ^0.19.3

I lost plenty of time because the flags: ^3.2.2 package was using flutter_svg: ^0.19.1 and it led to the same error.

like image 24
Daniele Manicardi Avatar answered Nov 17 '22 14:11

Daniele Manicardi