-
This requires the 'extension-methods' experiment to be enabled.Flutter/errors and solved 2020. 5. 15. 12:59
An error may occur when trying to use an extension in Flutter as shown below.
extension NumberParsing on String { int parseInt() { return int.parse(this); } double parseDouble() { return double.parse(this); } }
There is no highlight in the extension text itself, and the error messages are:
error: This requires the 'extension-methods' experiment to be enabled. (experiment_not_enabled at [ble_flutter_example] lib \ main.dart: 18)
error: Functions must have an explicit list of parameters. (missing_function_parameters at [ble_flutter_example] lib \ main.dart: 18)
error: Undefined class 'extension'. (undefined_class at [ble_flutter_example] lib \ main.dart: 18)
error: Undefined class 'on'. (undefined_class at [ble_flutter_example] lib \ main.dart: 18)
error: Invalid reference to 'this' expression. (invalid_reference_to_this at [ble_flutter_example] lib \ main.dart: 20)
First, let's check the extension with the following command in the project.
> dartanalyzer --enable-experiment extension-methods.
hint-Extension methods weren't supported until version 2.6.0, but this code is required to be able to run on earlier versions.
Extension is supported from SDK version 2.6.0, but the project is configured to support (execute) even the following versions.
In other words, the extension function itself supports from 2.6.0, but the project has a minimum SDK version that is too low.
The solution is to upload at least the sdk version.
Open the pubspec.yaml file and change the sdk version to 2.6.0 or higher.
pubspec.yaml environment: sdk: ">=2.6.0 <3.0.0"
Then upgrade the pub from the terminal.
> flutter pub upgrade
If you keep doing this and you still get the error, turn off the IDE and turn it on.
'Flutter > errors and solved' 카테고리의 다른 글