Flutter widget: AspectRatio final double aspectRatio;paint Variables must be declared using the keywords 'const', 'final', 'var' or a type name

47 views Asked by At

I got a weird error when trying to run the project (It's work perfectly the previous day!). And the problem is cause by declaring the variable in AspectRatio as image below. Currently, I use flutter version 3.10.0 and try to clean and flutter pub get but the issue is still happening.

enter image description here

Launching lib/main_qc.dart on SM A536E in debug mode...
Running Gradle task 'assembleQcDebug'...
../development/flutter/packages/flutter/lib/src/widgets/basic.dart:3375:28: Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
Try adding the name of the type of the variable or the keyword 'var'.
  final double aspectRatio;paint
                           ^^^^^
../development/flutter/packages/flutter/lib/src/widgets/basic.dart:3375:28: Error: Expected ';' after this.
  final double aspectRatio;paint
                           ^^^^^
../development/flutter/packages/flutter/lib/src/widgets/basic.dart:3365:9: Error: Constructor is marked 'const' so all fields must be final.
  const AspectRatio({
        ^
../development/flutter/packages/flutter/lib/src/widgets/basic.dart:3375:28: Context: Field isn't final, but constructor is 'const'.
  final double aspectRatio;paint
                           ^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script '/Users/admin/development/flutter/packages/flutter_tools/gradle/src/main/groovy/flutter.groovy' line: 1297

* What went wrong:
Execution failed for task ':app:compileFlutterBuildQcDebug'.
> Process 'command '/Users/admin/development/flutter/bin/flutter'' 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 52s
Exception: Gradle task assembleQcDebug failed with exit code 1

[!] Flutter (Channel stable, 3.13.1, on macOS 13.5.1 22G90 darwin-x64, locale en-VN)
    • Flutter version 3.13.1 on channel stable at /Users/admin/development/flutter
    ! Warning: `dart` on your path resolves to /usr/local/Cellar/dart/3.1.0/libexec/bin/dart, which is not
      inside your current Flutter SDK checkout at /Users/admin/development/flutter. Consider adding
      /Users/admin/development/flutter/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e1e47221e8 (5 months ago), 2023-08-22 21:43:18 -0700
    • Engine revision b20183e040
    • Dart version 3.1.0
    • DevTools version 2.25.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git"
      directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/admin/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.85.1)
    • VS Code at /Users/admin/development/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (4 available)            
    • SM A536E (mobile)      • R5CT40W12LL                          • android-arm64  
[✓] Network resources
    • All expected network resources are available.

1

There are 1 answers

0
Md. Yeasin Sheikh On

You can remove that paint, which will be like

 final double aspectRatio;

You can find the src. Also you do a force upgrade flutter upgrade -f