How to decorate text stroke in Flutter?

前端 未结 5 939
孤独总比滥情好
孤独总比滥情好 2020-12-17 09:14

How to decorate text stroke in Flutter? It\'s like -webkit-text-stroke - CSS

5条回答
  •  心在旅途
    2020-12-17 09:45

    Stroke has been possible without workarounds since the addition of foreground paints in TextStyle. An explicit example of stroke under fill bordered text has been added in the TextStyle documentation: https://master-api.flutter.dev/flutter/painting/TextStyle-class.html#painting.TextStyle.6

    This example is reproduced here:

    Stack(
      children: [
        // Stroked text as border.
        Text(
          'Greetings, planet!',
          style: TextStyle(
            fontSize: 40,
            foreground: Paint()
              ..style = PaintingStyle.stroke
              ..strokeWidth = 6
              ..color = Colors.blue[700],
          ),
        ),
        // Solid text as fill.
        Text(
          'Greetings, planet!',
          style: TextStyle(
            fontSize: 40,
            color: Colors.grey[300],
          ),
        ),
      ],
    )
    

    Stroke by itself is possible by removing the Stack and just using the first stroke Text widget by itself. The stroke/fill order can also be adjusted by swapping the first and second Text widget.

提交回复
热议问题