import 'package:flutter/material.dart'; /* * 表单中必填的文本描述,文本后加红色*标识 * 使用富文本的方式实现 */ class FormRequireText extends StatelessWidget { final String text; FontWeight? fontWeight; Color? textColor = Colors.black; 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 ?? FontWeight.w500, color: textColor), children: [ TextSpan( text: text, ), const TextSpan( text: " *", style: TextStyle(color: Colors.red), ), ], ), ); } }