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.48k stars 150 forks source link

[BUG]: Import conflict: Image class defined in flutter and rive #545

Closed codeOfJannik closed 3 months ago

codeOfJannik commented 3 months ago

Is there an existing issue for this?

Version

5.6.0

Command type

build_runner (Default)

What happened?

Out of nowhere we started to get an error in the generated file that a image class is found both in package/flutter/...widgets.dart and package/rive: The name 'Image' is defined in the libraries 'package:flutter/src/widgets/image.dart (via package:flutter/widgets.dart)' and 'package:rive/src/rive_core/shapes/image.dart (via package:rive/rive.dart)'.

Anyone else already faced that issue? Has anything changed in the package? Or did something change in rive, e.g. they started to export the image class so it's visible?

A workaround for now is to add a hide Image to the rive import manually after the assets.gen.dart file has been generated.

Our assets folder contains png, jpg, svg and riv files.

Relevant a pubspec.yaml.

dependencies:
  flutter:
    sdk: flutter
  flutter_svg: ^2.0.10+1
  rive: ^0.13.12

dev_dependencies:
  build_runner: ^2.4.11
  flutter_gen_runner: ^5.6.0
  flutter_test:
    sdk: flutter

flutter:
  assets:
    - assets/
    - assets/animations/
    - assets/images/
    - assets/images/first_time_ux/
    - assets/images/first_time_ux/alerting/de/
    - assets/images/first_time_ux/alerting/en/
    - assets/images/group/
    - assets/images/menu_icons/

flutter_gen:
  output: lib/src/generated/
  line_length: 180
  assets:
    outputs:
      package_parameter_enabled: true

  integrations:
    flutter_svg: true
    rive: true

Relevant log output

FlutterGen v5.6.0 Loading ... pubspec.yaml
[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 903ms

[INFO] Checking for unexpected pre-existing outputs....
[INFO] Deleting 1 declared outputs which already existed on disk.
[INFO] Checking for unexpected pre-existing outputs. completed, took 2ms

[INFO] Running build...
Generated: lib/src/generated/assets.gen.dart
FlutterGen finished.

Code of Conduct

mhammerc commented 3 months ago

Hello,

The error appears starting with rive version 0.13.10.

Version 0.13.9 doesn't export Image. For now, we will stay on rive 0.13.9 so we "avoid" this error.

AlexV525 commented 3 months ago

Sounds like a rive issue which means the issue should be reported to the rive package?

codeOfJannik commented 3 months ago

Why? If the rive package needs to export the image class they can do that. The flutter_gen rive import statement should be adjusted to hide Image from rive

Sevastyan commented 3 months ago

Not hide, but flutter_gen must have been using aliases for imports in the first place. Otherwise, the issue might return.

AlexV525 commented 3 months ago

We have a relatively long releasing procedure. If you're encountering the issue you can use the fix in the PR https://github.com/FlutterGen/flutter_gen/pull/548 by overriding dependencies.

mhammerc commented 3 months ago

We have a relatively long releasing procedure. If you're encountering the issue you can use the fix in the PR #548 by overriding dependencies.

Hello,

Just wanted to say thank you for the upcoming fix and the ongoing support of flutter_gen. This is what makes the Flutter community thrive, and it helps many.

msxenon commented 3 months ago

its better to use import alias just like mockito generator)

usmanovrustam commented 2 months ago

The Issue is closed, anyway I fixed problem by using older version of rive(0.13.5). Idk why contributors of rive added Image class in the new version!

AlexV525 commented 2 months ago

The issue is closed because the fix has been shipped through the v5.7.0 version.

usmanovrustam commented 2 months ago

The issue is closed because the fix has been shipped through the v5.7.0 version.

I am using v5.7.0 version. but there was the same issue

AlexV525 commented 2 months ago

The issue is closed because the fix has been shipped through the v5.7.0 version.

I am using v5.7.0 version. but there was the same issue

Attach more details?

usmanovrustam commented 2 months ago

The issue is closed because the fix has been shipped through the v5.7.0 version.

I am using v5.7.0 version. but there was the same issue

Attach more details?

these are my current dependencies:


dependencies:
  flutter:
    sdk: flutter
  rive: 0.13.13
  flutter_svg: 2.0.10+1

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: 4.0.0
  build_runner: 2.4.12
  flutter_gen_runner: 5.7.0

And this is the error :

Screenshot 2024-09-03 at 14 51 37

AlexV525 commented 2 months ago

Make sure they are both v5.7.0 image

usmanovrustam commented 2 months ago

Make sure they are both v5.7.0 image

Screenshot 2024-09-03 at 18 39 57

Yes, they are.

AlexV525 commented 2 months ago

Probably because you are using fluttergen command rather than the build_runner, the discussion is out of the topic of the thread.