fislabelinputfield.dart 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import 'package:flutter/material.dart';
  2. import 'package:flyinsonolite/infrastructure/scale.dart';
  3. import 'package:flyinsonolite/infrastructure/storage.dart';
  4. class FISLabelInputField extends StatelessWidget {
  5. /// 是否必填
  6. final bool isRequired;
  7. final String label;
  8. /// 组件
  9. final Widget widget;
  10. final double width;
  11. final double? height;
  12. final double? labelWidth;
  13. final EdgeInsetsGeometry? labelPadding;
  14. final EdgeInsetsGeometry? padding;
  15. final Color? labelColor;
  16. final double minHeight;
  17. const FISLabelInputField(this.isRequired, this.label, this.widget, this.width,
  18. {super.key,
  19. this.height,
  20. this.padding,
  21. this.labelWidth,
  22. this.labelColor,
  23. this.minHeight = 0,
  24. this.labelPadding});
  25. @override
  26. Widget build(BuildContext context) {
  27. return Container(
  28. margin: EdgeInsets.symmetric(horizontal: 5.s),
  29. padding: padding,
  30. width: width - 11.s, //多1是因为缩放会有误差
  31. child: Flex(
  32. direction: Axis.horizontal,
  33. crossAxisAlignment: CrossAxisAlignment.start,
  34. children: [
  35. Container(
  36. padding: labelPadding ?? const EdgeInsets.all(0),
  37. width: labelWidth,
  38. alignment: Alignment.centerLeft,
  39. child: RichText(
  40. text: TextSpan(
  41. style: labelColor == null
  42. ? Storage
  43. .currentTheme.fisLabelInputFieldStyle.labelTextStyle
  44. .copyWith(
  45. fontSize: Storage
  46. .currentTheme
  47. .fisLabelInputFieldStyle
  48. .labelTextStyle
  49. .fontSize!
  50. .s)
  51. : Storage
  52. .currentTheme.fisLabelInputFieldStyle.labelTextStyle
  53. .copyWith(
  54. color: labelColor,
  55. fontSize: Storage
  56. .currentTheme
  57. .fisLabelInputFieldStyle
  58. .labelTextStyle
  59. .fontSize!
  60. .s),
  61. children: [
  62. TextSpan(
  63. text: label,
  64. ),
  65. if (isRequired) ...[
  66. TextSpan(
  67. text: ' * ',
  68. style: Storage
  69. .currentTheme.fisLabelInputFieldStyle.labelTextStyle
  70. .copyWith(
  71. color: Colors.red,
  72. fontSize: Storage
  73. .currentTheme
  74. .fisLabelInputFieldStyle
  75. .labelTextStyle
  76. .fontSize!
  77. .s),
  78. )
  79. ]
  80. ],
  81. ),
  82. textAlign: TextAlign.left,
  83. ),
  84. ),
  85. Expanded(
  86. child: Container(
  87. constraints: BoxConstraints(minHeight: minHeight),
  88. margin: EdgeInsets.fromLTRB(5.s, 0, 0, 0),
  89. height: height,
  90. child: widget,
  91. ))
  92. ],
  93. ),
  94. );
  95. }
  96. }
  97. class FISLabelInputFieldWithWrap extends StatelessWidget {
  98. /// 是否必填
  99. final bool isRequired;
  100. final String label;
  101. /// 组件
  102. final Widget widget;
  103. final double? width;
  104. final double? height;
  105. final double? labelWidth;
  106. final EdgeInsetsGeometry? labelPadding;
  107. final EdgeInsetsGeometry? padding;
  108. final Color? labelColor;
  109. final double minHeight;
  110. const FISLabelInputFieldWithWrap(
  111. this.isRequired, this.label, this.widget, this.width,
  112. {super.key,
  113. this.height,
  114. this.padding,
  115. this.labelWidth,
  116. this.labelColor,
  117. this.minHeight = 0,
  118. this.labelPadding});
  119. @override
  120. Widget build(BuildContext context) {
  121. return Container(
  122. padding: padding,
  123. width: width,
  124. child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
  125. Container(
  126. padding: labelPadding ?? EdgeInsets.fromLTRB(0, 12.s, 0, 0),
  127. width: labelWidth,
  128. alignment: Alignment.centerLeft,
  129. child: RichText(
  130. text: TextSpan(
  131. style: labelColor == null
  132. ? Storage
  133. .currentTheme.fisLabelInputFieldStyle.labelTextStyle
  134. .copyWith(
  135. fontSize: Storage
  136. .currentTheme
  137. .fisLabelInputFieldStyle
  138. .labelTextStyle
  139. .fontSize!
  140. .s)
  141. : Storage
  142. .currentTheme.fisLabelInputFieldStyle.labelTextStyle
  143. .copyWith(
  144. color: labelColor,
  145. fontSize: Storage
  146. .currentTheme
  147. .fisLabelInputFieldStyle
  148. .labelTextStyle
  149. .fontSize!
  150. .s),
  151. children: [
  152. TextSpan(text: label),
  153. if (isRequired) ...[
  154. TextSpan(
  155. text: ' * ',
  156. style: Storage
  157. .currentTheme.fisLabelInputFieldStyle.labelTextStyle
  158. .copyWith(
  159. color: Colors.red,
  160. fontSize: Storage
  161. .currentTheme
  162. .fisLabelInputFieldStyle
  163. .labelTextStyle
  164. .fontSize!
  165. .s),
  166. )
  167. ]
  168. ],
  169. ),
  170. textAlign: TextAlign.left,
  171. ),
  172. ),
  173. Expanded(child: widget)
  174. ]));
  175. }
  176. }