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

[FR]: Fonts weight #483

Open
2 tasks done
mustafa-fahimi opened this issue Mar 15, 2024 · 2 comments
Open
2 tasks done

[FR]: Fonts weight #483

mustafa-fahimi opened this issue Mar 15, 2024 · 2 comments
Labels
contributions welcome Welcome contribute enhancement New feature or request

Comments

@mustafa-fahimi
Copy link

Is there an existing issue for this?

  • 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

  • I agree to follow this project's Code of Conduct
@mustafa-fahimi mustafa-fahimi added the enhancement New feature or request label Mar 15, 2024
@AlexV525
Copy link
Member

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.

@mustafa-fahimi
Copy link
Author

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:

  1. Pubspec Configuration: In the pubspec.yaml file, 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
  1. Font Class Generation: Instead of generating a single RobotoFont class, we would generate separate classes for each weight variant, such as RobotoRegularFont, RobotoBoldFont, and RobotoLightFont. 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.

  2. Font Usage: In the Flutter application code, developers can then instantiate the appropriate FontWeight subclass based on the desired weight. For example:

Text(
  'Regular Text',
  style: TextStyle(fontFamily: RobotoRegularFont().family),
)

Text(
  'Bold Text',
  style: TextStyle(fontFamily: RobotoBoldFont().family),
)
  1. Dynamic Font-Weight Selection: To support dynamic font-weight selection, we could introduce a new method in the FontWeight base class, such as FontWeight.forValue(int weight), which would return an instance of the appropriate FontWeight subclass 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.

@AlexV525 AlexV525 added the contributions welcome Welcome contribute label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions welcome Welcome contribute enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants