flutter_gen
                                
                                
                                
                                    flutter_gen copied to clipboard
                            
                            
                            
                        [FR]: Fonts weight
Is there an existing issue for this?
- [X] I have searched the existing issues
 
Describe the problem
Hi. Generated fonts do not have weight and ignore given weight inside pubspec.yaml. Please add weight to fonts
Describe the solution
Add weight to fonts
Additional context
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
 
We need to create new classes for fonts if we want to include font-weight. It would be great if you could provide your idea about how you imagine the font-weight works.
After giving this some thought, I believe the best approach would be to introduce a new set of classes that represent font-weight variations. This approach would maintain the existing code structure and functionality while providing a clean and extensible way to handle font-weights.
Specifically, I propose the following implementation:
- Pubspec Configuration: In the 
pubspec.yamlfile, allow users to specify the font-weight for each font file they define. For example: 
flutter:
  fonts:
    - family: Roboto
      fonts:
        - asset: fonts/Roboto-Regular.ttf
          weight: 400
        - asset: fonts/Roboto-Bold.ttf
          weight: 700
        - asset: fonts/Roboto-Light.ttf
          weight: 300
- 
Font Class Generation: Instead of generating a single
RobotoFontclass, we would generate separate classes for each weight variant, such asRobotoRegularFont,RobotoBoldFont, andRobotoLightFont. These classes would extend a new base class,FontWeight, which would encapsulate the weight value and provide a consistent interface for accessing and using the font weight. - 
Font Usage: In the Flutter application code, developers can then instantiate the appropriate
FontWeightsubclass based on the desired weight. For example: 
Text(
  'Regular Text',
  style: TextStyle(fontFamily: RobotoRegularFont().family),
)
Text(
  'Bold Text',
  style: TextStyle(fontFamily: RobotoBoldFont().family),
)
- Dynamic Font-Weight Selection: To support dynamic font-weight selection, we could introduce a new method in the 
FontWeightbase class, such asFontWeight.forValue(int weight), which would return an instance of the appropriateFontWeightsubclass based on the provided weight value. This would allow developers to use numerical weight values (e.g.,FontWeight.w500) or even create custom weight variations if needed. 
This approach would provide a robust and type-safe way to handle font-weights while maintaining the existing code generation and usage patterns. It would also ensure that the font-weight information is correctly propagated from the pubspec.yaml configuration to the generated code and ultimately to the Flutter application.
Additionally, this implementation would be extensible, allowing for future enhancements such as support for font-stretch, font-style, or other font-related properties.