问题
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
回答1:
Follow the steps below
- add the following dependency
flutter_svg: ^0.20.0-nullsafety.3
- run
flutter clean
command - run
flutter pub get
command - run
flutter run
command or run the project
回答2:
The problem is that the version of Flutter with null-safety enabled (currently on the beta channel as of writing), the nullOk
parameter was removed Localizations.localeOf
, but you're using a package (in this case, flutter_svg
) that is still using nullOk
.
If you're using the null-safe version of Flutter, you should use null-safe versions of other packages too, if available. Alternatively you can stick with the latest version of Flutter without null-safety (version 1.22.x) until all of your dependent packages have been migrated for null-safety.
来源:https://stackoverflow.com/questions/66144283/how-to-fix-this-nullok-error-when-using-the-flutter-svg-package