代码
class AutoSizeRichTextExample extends StatelessWidget { @override Widget build(BuildContext context) { final List<Map<String, dynamic>> dataList = [ {'text': 'This ', 'color': Colors.red}, {'text': 'is ', 'color': Colors.blue}, {'text': 'a ', 'color': Colors.green}, {'text': 'slightly ', 'color': Colors.orange}, {'text': 'longer ', 'color': Colors.purple}, {'text': 'item', 'color': Colors.teal} ]; return Center( child: Container( color: Colors.white, child: ColoredTextWithStroke( dataList: dataList, ), ), ); } } class ColoredTextWithStroke extends StatelessWidget { final List<Map<String, dynamic>> dataList; ColoredTextWithStroke({required this.dataList}); @override Widget build(BuildContext context) { return FittedBox( fit: BoxFit.scaleDown, child: Row( mainAxisSize: MainAxisSize.min, children: List.generate(dataList.length, (index) { final item = dataList[index]; return OutlinedText( text: item['text'], style: TextStyle( fontWeight: FontWeight.bold, color: item['color'], fontSize: 70, ), strokeWidth: 2.0, strokeColor: Colors.black, // Stroke color ); })), ); } }