import 'package:flutter/material.dart'; /** * 表单中必填的文本描述,文本后加红色*标识 * 使用富文本的方式实现 */ class FormRequireText extends StatelessWidget { final String text; FontWeight? fontWeight = FontWeight.w400; Color? textColor = Colors.white; double? fontSize = 15.0; FormRequireText({required this.text, this.textColor, this.fontSize, this.fontWeight}); @override Widget build(BuildContext context) { return RichText( text: TextSpan( style: TextStyle(fontSize: fontSize, fontWeight: fontWeight, color: textColor), children: [ TextSpan( text: text, ), TextSpan( text: " *", style: TextStyle(color: Colors.red), ), ], ), ); } }