FlutterGen / flutter_gen

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.
https://pub.dev/packages/flutter_gen
MIT License
1.46k stars 146 forks source link

[BUG]: Including folders 1.0x, 2.0x, 3.0x, causes exception #444

Closed BenjiFarquhar closed 10 months ago

BenjiFarquhar commented 10 months ago

Is there an existing issue for this?

Version

5.3.2

Command type

build_runner (Default)

What happened?

This works:

  assets:
    - assets/images/
    # - assets/images/2.0x/
    # - assets/images/3.0x/
    - assets/map_styles/
this doesn't:
  assets:
    - assets/images/
    - assets/images/2.0x/
    - assets/images/3.0x/
    - assets/map_styles/

this is all of the images in those 2.0x and 3.0x folders (they have the exact same file names in both):

Screenshot 2023-10-27 at 18 37 15

Relevant a pubspec.yaml.

name: x
publish_to: "none"
version: 0.0.2+1

environment:
  sdk: '>=3.0.0 <4.0.0'

dependencies:
  analyzer: ^6.2.0
  animate_do: ^3.1.2
  basic_utils: ^5.6.1
  collection: ^1.18.0
  connectivity_plus: ^4.0.2
  dio: ^5.3.3
  duration: ^3.0.13
  firebase_analytics: 10.5.1
  firebase_auth: 4.10.1
  firebase_core: 2.17.0
  flash: ^3.0.5+1
  flutter:
    sdk: flutter
  flutter_launcher_icons: ^0.13.1
  flutter_localizations:
    sdk: flutter
  flutter_native_splash: ^2.3.3
  flutter_riverpod: ^2.4.3
  flutter_typeahead: ^4.8.0
  font_awesome_flutter: ^10.5.0
  freezed: ^2.4.3
  freezed_annotation: ^2.4.1
  geolocator: ^10.1.0
  google_maps_flutter: ^2.5.0
  google_maps_flutter_android: ^2.5.1
  google_maps_flutter_platform_interface: 2.4.1
  google_maps_flutter_web: ^0.5.4+2
  hive: ^2.2.3
  hive_flutter: ^1.1.0
  hive_generator: ^2.0.1
  image_cropper: ^5.0.0
  image_picker: ^1.0.4
  intl: ^0.18.1
  json_annotation: ^4.8.1
  json_serializable: ^6.7.1
  loading_animation_widget: ^1.2.0+4
  reactive_forms: ^16.1.0
  reactive_forms_annotations: ^4.2.0
  retrofit: ^4.0.2
  sentry_flutter: ^7.10.1
  sentry_dart_plugin: ^1.6.2
  smooth_page_indicator: ^1.1.0
  stack_trace: 
  string_validator: ^1.0.0
  # mockito: 5.4.2
  uuid: ^3.0.7
  animated_text_kit: ^4.2.2
  riverpod_annotation: ^2.2.0
  go_router: ^11.1.2
  flutter_rating_bar: ^4.0.1
  flutter_staggered_grid_view: ^0.7.0
  auto_size_text: ^3.0.0
  pointer_interceptor: ^0.9.3+6
  universal_io: ^2.2.2
  universal_html: ^2.2.4
  url_launcher: ^6.1.14
  reactive_forms_lbc: ^3.0.0
dependency_overrides:
  intl: 0.18.0
  collection: 1.17.1
  font_awesome_flutter:
    path: font_awesome_flutter-master

dev_dependencies:
  build_runner: ^2.4.6
  flutter_gen_runner: ^5.3.2
  flutter_lints: ^2.0.3
  # flutter_test:
  #   sdk: flutter
  reactive_forms_generator: ^4.2.0
  retrofit_generator: 8.0.0
  riverpod_generator: ^2.3.3
  # test:

flutter:
  uses-material-design: true
  fonts:
    - family: Hind
      fonts:
        - asset: assets/fonts/hind/Hind-Medium.ttf
          weight: 500
        - asset: assets/fonts/hind/Hind-Light.ttf
          weight: 300
        - asset: assets/fonts/hind/Hind-Regular.ttf
          weight: 400
        - asset: assets/fonts/hind/Hind-Bold.ttf
          weight: 700
        - asset: assets/fonts/hind/Hind-SemiBold.ttf
          weight: 600
    - family: Poppins
      fonts:
        - asset: assets/fonts/poppins/Poppins-Black.ttf
          weight: 900
        - asset: assets/fonts/poppins/Poppins-BlackItalic.ttf
          weight: 900
          style: italic
        - asset: assets/fonts/poppins/Poppins-Bold.ttf
          weight: 700
        - asset: assets/fonts/poppins/Poppins-BoldItalic.ttf
          weight: 700
          style: italic
        - asset: assets/fonts/poppins/Poppins-ExtraBold.ttf
          weight: 800
        - asset: assets/fonts/poppins/Poppins-ExtraBoldItalic.ttf
          weight: 800
          style: italic
        - asset: assets/fonts/poppins/Poppins-ExtraLight.ttf
          weight: 200
        - asset: assets/fonts/poppins/Poppins-ExtraLightItalic.ttf
          weight: 200
          style: italic
        - asset: assets/fonts/poppins/Poppins-Italic.ttf
          weight: 400
          style: italic
        - asset: assets/fonts/poppins/Poppins-Regular.ttf
          weight: 400
        - asset: assets/fonts/poppins/Poppins-Light.ttf
          weight: 300
        - asset: assets/fonts/poppins/Poppins-LightItalic.ttf
          weight: 300
          style: italic
        - asset: assets/fonts/poppins/Poppins-Medium.ttf
          weight: 500
        - asset: assets/fonts/poppins/Poppins-MediumItalic.ttf
          weight: 500
          style: italic
        - asset: assets/fonts/poppins/Poppins-SemiBold.ttf
          weight: 600
        - asset: assets/fonts/poppins/Poppins-SemiBoldItalic.ttf
          weight: 600
          style: italic
        - asset: assets/fonts/poppins/Poppins-Thin.ttf
          weight: 100
        - asset: assets/fonts/poppins/Poppins-ThinItalic.ttf
          weight: 100
          style: italic
    - family: FashionItm
      fonts:
        - asset: assets/fonts/FashionItem.ttf
  assets:
    - assets/images/
    - assets/images/2.0x/
    - assets/images/3.0x/
    - assets/map_styles/

flutter_gen:
  output: lib/config

flutter_native_splash:
  image: assets/images/splash_screen.png
  color: "#FFFFFF"

Relevant log output

Unhandled exception:
Could not format because the source could not be parsed:

line 17, column 23 of .: Expected to find ';'.
   ╷
17 │   $AssetsImages20xGen get 2 => const $AssetsImages20xGen();
   │                       ^^^
   ╵
line 17, column 27 of .: Expected a class member.
   ╷
17 │   $AssetsImages20xGen get 2 => const $AssetsImages20xGen();
   │                           ^
   ╵
line 17, column 29 of .: Expected an identifier.
   ╷
17 │   $AssetsImages20xGen get 2 => const $AssetsImages20xGen();
   │                             ^^
   ╵
line 17, column 29 of .: Methods must have an explicit list of parameters.
   ╷
17 │   $AssetsImages20xGen get 2 => const $AssetsImages20xGen();
   │                             ^^
   ╵
line 18, column 21 of .: Expected to find ';'.
   ╷
18 │ $AssetsImages30xGen get 3 => const $AssetsImages30xGen();
   │                     ^^^
   ╵
line 18, column 25 of .: Expected a class member.
   ╷
18 │ $AssetsImages30xGen get 3 => const $AssetsImages30xGen();
   │                         ^
   ╵
line 18, column 27 of .: Expected an identifier.
   ╷
18 │ $AssetsImages30xGen get 3 => const $AssetsImages30xGen();
   │                           ^^
   ╵
line 18, column 27 of .: Methods must have an explicit list of parameters.
   ╷
18 │ $AssetsImages30xGen get 3 => const $AssetsImages30xGen();
   │                           ^^
   ╵
#0      DartFormatter.formatSource (package:dart_style/src/dart_formatter.dart:151)
#1      DartFormatter.format (package:dart_style/src/dart_formatter.dart:83)
#2      generateAssets (package:flutter_gen_core/generators/assets_generator.dart:186)
#3      FlutterGenerator.build (package:flutter_gen_core/flutter_generator.dart:60)
#4      main (file:///Users/runner/work/flutter_gen/flutter_gen/packages/command/bin/flutter_gen_command.dart:48)
#5      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:294)
#6      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189)

Code of Conduct

lcdsmao commented 10 months ago
  assets:
    - assets/images/
    # - assets/images/2.0x/
    # - assets/images/3.0x/
    - assets/map_styles/

This is the correct way to specify assets. There is no need to add 2.0x and 3.0x. Please check the documentation: https://docs.flutter.dev/ui/assets/assets-and-images#resolution-aware

BenjiFarquhar commented 10 months ago

@lcdsmao Ah, I see. Thanks!

MrLittleWhite commented 7 months ago

@lcdsmao Ah, I see. Thanks!

  assets:
    - assets/images/
    # - assets/images/2.0x/
    # - assets/images/3.0x/
    - assets/map_styles/

This is the correct way to specify assets. There is no need to add 2.0x and 3.0x. Please check the documentation: https://docs.flutter.dev/ui/assets/assets-and-images#resolution-aware

if do this, did not generate image assets code, any solution? FlutterGen v5.3.2