Skip to content

Conversation

Abdalqader27
Copy link
Contributor

@Abdalqader27 Abdalqader27 commented May 28, 2025

Description

  • A new copyWithStyle property of type StacTextStyle? has been introduced to both StacText and StacTextSpan. This allows for selectively overriding properties of a predefined base text style.

Enhanced style merging behavior:

  • The copyWithStyle property enables developers to build on top of existing styles (e.g., "labelMedium") by overriding specific attributes such as color, font weight, or letter spacing, without redefining the entire style.

Updated StacTextParser:

  • Introduced a _resolveStyle method to merge style and copyWithStyle values into a single TextStyle, giving priority to the override values from copyWithStyle.

  • The _buildTextSpan method now applies _resolveStyle to each child span, ensuring consistent style resolution.

Example:

{
  "type": "text",
  "data": "Hello, ",
  "style": "bodyLarge",
  "copyWithStyle": {
    "color": "#000000"
  },
  "children": [
    {
      "data": "John",
      "style": "bodyLarge",
      "copyWithStyle": {
        "color": "#2196F3",
        "fontWeight": "bold"
      }
    },
    {
      "data": "! Welcome to ",
      "style": "bodyLarge"
    },
    {
      "data": "Flutter",
      "style": "bodyLarge",
      "copyWithStyle": {
        "color": "#4CAF50",
        "fontStyle": "italic",
        "decoration": "underline"
      }
    },
    {
      "data": " world.",
      "style": "bodyLarge"
    }
  ]
}

Related Issues

Closes #249

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Code refactor
  • Build configuration change
  • Documentation
  • Chore

@divyanshub024
Copy link
Member

Hey @Abdalqader27!! Thank you for this amazing PR. There are some formatting issues. Can you please check them?

https://github.com/StacDev/stac/actions/runs/15293316177/job/43023165207?pr=262

@Abdalqader27
Copy link
Contributor Author

Hey @Abdalqader27!! Thank you for this amazing PR. There are some formatting issues. Can you please check them?

https://github.com/StacDev/stac/actions/runs/15293316177/job/43023165207?pr=262

You 're welcome @divyanshub024 , SOLVED

@Abdalqader27
Copy link
Contributor Author

@divyanshub024 now we 're good

Copy link
Member

@divyanshub024 divyanshub024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @Abdalqader27 🎉

@divyanshub024 divyanshub024 merged commit 0c791af into StacDev:dev May 28, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add support for the style copyWith

2 participants