andyduke / styled_text_package

Text widget with formatted text using tags. Makes it easier to use formatted text in multilingual applications.
https://pub.dev/packages/styled_text
BSD 3-Clause "New" or "Revised" License
74 stars 48 forks source link

Is it possible to pass StyledText.style to StyledTextTagBase #82

Open fingerart opened 3 weeks ago

fingerart commented 3 weeks ago

Example 1:

  // <linear-gradient from="theme_color_name|hex_number" to="theme_color_name|hex_number" />
  'linear-gradient': StyledTextWidgetBuilderTag(
    (context, attributes, text) {
      final from = attributes['from'];
      final to = attributes['to'];
      Color? fromColor = _parseColor(context, from);
      Color? toColor = _parseColor(context, to);

      return ShaderMask(
        shaderCallback: (rect) => LinearGradient(
          colors: [fromColor, toColor],
          begin: Alignment.topLeft,
          end: Alignment.topRight,
        ).createShader(rect),
        child: Text(text, style: style), // Unable to inherit size of StyledText.style
      );
    },
    alignment: PlaceholderAlignment.baseline,
  ),

Example 2:

// <font size="relative_size" />
'font': StyledTextCustomTag(parse: (context, baseStyle, attributes) {
    final rawSize = attributes['size'];// Support relative size

   fial size = StyledText.style.copyWith(size: StyledText.style.size + rawSize);

    return TextStyle(fontSize: size);
  }),