Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Need option to generate only String constants without AssetGenImage #636

Closed
2 tasks done
houzixiashanxiedaima opened this issue Jan 22, 2025 · 0 comments · Fixed by #645
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@houzixiashanxiedaima
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Version

5.8.0

Command type

build_runner (Default)

What happened?

Description

Currently, FlutterGen always generates AssetGenImage types for image assets. In our project, we need to use only String constants for asset paths (like static const String imagesLogo = 'assets/images/logo.png') without the AssetGenImage wrapper class. This is particularly important for projects migrating from string-based asset references or maintaining compatibility with existing codebases.

Current Behavior

class Assets {
    static const AssetGenImage imagesLogo = AssetGenImage('assets/images/logo.png');
}

Desired Behavior

class Assets {
    static const String imagesLogo = 'assets/images/logo.png';
}

Relevant a pubspec.yaml.

#资源文件生成配置
flutter_gen:
  output: lib/generated/ # 输出目录
  line_length: 80 # 行长度,过长时会自动换行
  
  integrations:
    flutter_svg: false   # 禁用 svg 集成
    flare_flutter: false # 禁用 flare 集成
    rive: false         # 禁用 rive 集成
    lottie: false       # 禁用 lottie 集成
    
  assets:
    outputs:
      class_name: Assets
      style: camel-case  # 使用驼峰命名
      package_parameter_enabled: false  # 不生成包参数

flutter:
  generate: false
  uses-material-design: true
  assets:
    - images/
    - images/2.0x/
    - images/3.0x/
    - audios/
    - assets/

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct
@houzixiashanxiedaima houzixiashanxiedaima added the bug Something isn't working label Jan 22, 2025
@houzixiashanxiedaima houzixiashanxiedaima changed the title [BUG]: Need option to generate only String constants without AssetGenImagean [BUG]: Need option to generate only String constants without AssetGenImage Jan 22, 2025
AlexV525 added a commit that referenced this issue Jan 29, 2025
## What does this change?

Adds the explicit and configurable image integration.

Resolves #636 🎯

## Type of change

- [x] New feature (non-breaking change which adds functionality)
- [x] This change requires a documentation update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant