form_require_text.dart 824 B

123456789101112131415161718192021222324252627282930313233
  1. import 'package:flutter/material.dart';
  2. /*
  3. * 表单中必填的文本描述,文本后加红色*标识
  4. * 使用富文本的方式实现
  5. */
  6. class FormRequireText extends StatelessWidget {
  7. final String text;
  8. FontWeight? fontWeight = FontWeight.w400;
  9. Color? textColor = Colors.white;
  10. double? fontSize = 15.0;
  11. FormRequireText({required this.text, this.textColor, this.fontSize, this.fontWeight});
  12. @override
  13. Widget build(BuildContext context) {
  14. return RichText(
  15. text: TextSpan(
  16. style: TextStyle(fontSize: fontSize, fontWeight: fontWeight, color: textColor),
  17. children: <TextSpan>[
  18. TextSpan(
  19. text: text,
  20. ),
  21. const TextSpan(
  22. text: " *",
  23. style: TextStyle(color: Colors.red),
  24. ),
  25. ],
  26. ),
  27. );
  28. }
  29. }