Skip to content

Text with ShaderMask with Gradient show unexpected black decoration and transparent spaces. #126867

@MiniSuperDev

Description

@MiniSuperDev

Is there an existing issue for this?

Steps to reproduce

Hi, I create a GradientText Widget which is a text that can have a gradient as border and other gradient as a fill, but on several occasions I can see that a black border is visible, and white space (as in the j dot), why?

I leave you a DartPad where you can reproduce it, there I exaggerated the border width so that the error can be seen well, but even if it is 1 or 2 in some words or fonts, the same thing happens

DartPad: https://dartpad.dev/?id=6cd64f9a428393d3d4f9290973e132de

Expected results

the border should have only the colors of the gradient.

Actual results

The border shows in addition to the gradient colors a black color and white spaces.

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: Center(
          child: GradientText(
            'jgoqupLy',
            fontSize: 40,
            borderWidth: 20,
            borderGradient: LinearGradient(
              colors: [
                Colors.yellow,
                Colors.green,
              ],
            ),
            fillGradient: LinearGradient(
              colors: [
                Colors.red,
                Colors.blue,
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class GradientText extends StatelessWidget {
  const GradientText(
    this.data, {
    super.key,
    required this.fontSize,
    required this.borderGradient,
    required this.fillGradient,
    required this.borderWidth,
  });

  final String data;
  final Gradient borderGradient;
  final Gradient fillGradient;
  final double borderWidth;
  final double fontSize;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        _buildGradientTextBase(
          gradient: borderGradient,
          paintingStyle: PaintingStyle.stroke,
        ),
        _buildGradientTextBase(
          gradient: fillGradient,
          paintingStyle: PaintingStyle.fill,
        ),
      ],
    );
  }

  Widget _buildGradientTextBase({
    required Gradient gradient,
    required PaintingStyle paintingStyle,
  }) {
    return ShaderMask(
      blendMode: BlendMode.srcIn,
      shaderCallback: (bounds) => gradient.createShader(
        Rect.fromLTWH(0, 0, bounds.width, bounds.height),
      ),
      child: Text(
        data,
        style: TextStyle(
          fontSize: fontSize,
          foreground: Paint()
            ..style = paintingStyle
            ..strokeWidth = borderWidth,
          fontWeight: FontWeight.bold,
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

image

Logs

Logs

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.10.0, on Microsoft Windows, locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.14)
[√] Android Studio (version 2020.3)
[√] VS Code (version 1.78.2)
[√] Connected device (3 available)
[√] Network resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: typographyText rendering, possibly libtxtdependency: skiaSkia team may need to help usengineflutter/engine related. See also e: labels.found in release: 3.10Found to occur in 3.10found in release: 3.11Found to occur in 3.11has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions