form_require_text.dart 957 B

12345678910111213141516171819202122232425262728293031323334353637
  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. bool? isRequired = true;
  12. FormRequireText({required this.text, this.textColor, this.fontSize, this.fontWeight, bool? isRequired}){
  13. this.isRequired = isRequired?? true;
  14. }
  15. @override
  16. Widget build(BuildContext context) {
  17. return RichText(
  18. text: TextSpan(
  19. style: TextStyle(fontSize: fontSize, fontWeight: fontWeight, color: textColor),
  20. children: <TextSpan>[
  21. TextSpan(
  22. text: text,
  23. ),
  24. if (isRequired == true)
  25. const TextSpan(
  26. text: " *",
  27. style: TextStyle(color: Colors.red),
  28. ),
  29. ],
  30. ),
  31. );
  32. }
  33. }