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]: Conflict between Image class in Flutter and Rive with Flutter Gen #559

Closed isaacadariku closed 2 months ago

isaacadariku commented 2 months ago

Is there an existing issue for this?

Version

5.6.0

Command type

Dart command

What happened?

There is a conflict when using the flutter_gen package with the rive dependency versions. The generated file has an ambiguous import error with the Image class from Flutter and Rive. This issue is caused by the overlapping Image class names in Flutter and Rive packages. A potential solution could be to use aliases or hide directives in the generated file.

Steps to Reproduce

  1. Use pubspec.yaml configuration.
  2. Add a sample Rive file (download from Rive Community) to the assets/rive/ folder.
  3. Add a sample image file to the assets/images/ folder.
  4. Run the command fluttergen to generate the required files.

Expected Behavior

The usage should be without any errors, and the generated file should properly integrate Rive and image assets.

Actual Behavior

The usage of image throws an error due to an ambiguous import of the Image class from both package:flutter/src/widgets/image.dart and package:rive/src/rive_core/shapes/image.dart.

For example, when using Assets.images.appIcon.image()

The argument type 'dynamic' can't be assigned to the parameter type 'Widget?'. dartargument_type_not_assignable

In the generated file

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)'.
Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.dartambiguous_import

Workaround

Downgrading rive to version 0.13.9 resolves the issue, but any version above causes the conflict.

Environment

Relevant a pubspec.yaml.

environment:
  sdk: ^3.5.1

dependencies:
  flutter:
    sdk: flutter
  rive: ^0.13.12

flutter:
  uses-material-design: true

  assets:
    - assets/images/
    - assets/rive/

flutter_gen:
  output: lib/generated
  integrations:
    rive: true

Relevant log output

No response

Code of Conduct

AlexV525 commented 2 months ago

Duplicate of #545