cell.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import 'package:flutter/material.dart';
  2. import 'package:vitalapp/consts/styles.dart';
  3. class VListFormCellGroup extends StatelessWidget {
  4. final List<Widget> children;
  5. final double? leadingIconWidth;
  6. final String? formTitle;
  7. final Function? onSelectedAll;
  8. const VListFormCellGroup({
  9. Key? key,
  10. required this.children,
  11. this.leadingIconWidth,
  12. this.formTitle,
  13. this.onSelectedAll,
  14. }) : super(key: key);
  15. @override
  16. Widget build(BuildContext context) {
  17. final divider = Divider(
  18. thickness: 1,
  19. color: Colors.grey.shade400,
  20. indent: leadingIconWidth,
  21. );
  22. final kids = <Widget>[_buildVListFromCellGroupTitle()];
  23. for (var i = 0; i < children.length; i++) {
  24. Widget kid = children[i];
  25. if (i > 0) {
  26. kids.add(divider);
  27. }
  28. kids.add(kid);
  29. }
  30. return Container(
  31. alignment: Alignment.center,
  32. padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20),
  33. decoration: BoxDecoration(
  34. color: Colors.white,
  35. borderRadius: GlobalStyles.borderRadius,
  36. ),
  37. child: Column(
  38. mainAxisSize: MainAxisSize.min,
  39. mainAxisAlignment: MainAxisAlignment.start,
  40. crossAxisAlignment: CrossAxisAlignment.start,
  41. children: kids,
  42. ),
  43. );
  44. }
  45. Widget _buildVListFromCellGroupTitle() {
  46. if (formTitle == null) {
  47. return const SizedBox();
  48. } else {
  49. return Container(
  50. padding: const EdgeInsets.only(bottom: 8),
  51. child: Row(
  52. children: [
  53. Text(
  54. formTitle!,
  55. textAlign: TextAlign.left,
  56. style: const TextStyle(
  57. fontSize: 30,
  58. fontWeight: FontWeight.bold,
  59. ),
  60. ),
  61. SizedBox(
  62. width: 15,
  63. ),
  64. if (onSelectedAll != null) ...[
  65. Text("是否一键填充默认值"),
  66. Checkbox(
  67. value: null,
  68. onChanged: (v) {
  69. if (v ?? false) {
  70. onSelectedAll?.call();
  71. }
  72. },
  73. )
  74. ],
  75. ],
  76. ),
  77. );
  78. }
  79. }
  80. }
  81. class VListFormCell extends StatelessWidget {
  82. final String? label;
  83. final Widget? labelWidget;
  84. final double? labelWidth;
  85. final String? content;
  86. final Widget? contentWidget;
  87. final VoidCallback? onTap;
  88. final double? height;
  89. final double? leadingIconWidth;
  90. final Widget? leadingIcon;
  91. final Widget? endIcon;
  92. final bool isRequired;
  93. const VListFormCell({
  94. super.key,
  95. this.label,
  96. this.labelWidget,
  97. this.labelWidth,
  98. this.content,
  99. this.contentWidget,
  100. this.onTap,
  101. this.height,
  102. this.leadingIcon,
  103. this.endIcon,
  104. this.leadingIconWidth,
  105. this.isRequired = false,
  106. }) : assert(label != null || labelWidget != null);
  107. @override
  108. Widget build(BuildContext context) {
  109. final h = height ?? 48;
  110. final children = <Widget>[];
  111. if (leadingIcon != null) {
  112. final leadingWidget = SizedBox(
  113. width: leadingIconWidth ?? h * .6,
  114. child: leadingIcon,
  115. );
  116. children.add(leadingWidget);
  117. }
  118. children.add(_buildLabel());
  119. children.add(Expanded(child: _buildRightPart()));
  120. return SizedBox(
  121. height: h,
  122. child: InkWell(
  123. onTap: onTap,
  124. child: Row(
  125. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  126. children: children,
  127. ),
  128. ),
  129. );
  130. }
  131. Widget _buildRightPart() {
  132. final children = <Widget>[];
  133. final contentChild = _buildContent();
  134. if (contentChild != null) {
  135. children.add(contentChild);
  136. }
  137. if (endIcon != null) {
  138. children.add(
  139. SizedBox(
  140. height: height ?? 40,
  141. child: _buildAction(),
  142. ),
  143. );
  144. }
  145. // if (onTap != null) {
  146. // children.add(
  147. // SizedBox(
  148. // height: height ?? 40,
  149. // child: _buildAction(),
  150. // ),
  151. // );
  152. // } else {
  153. // children.add(const SizedBox(width: 12));
  154. // }
  155. return Row(
  156. mainAxisAlignment: MainAxisAlignment.end,
  157. mainAxisSize: MainAxisSize.max,
  158. children: children,
  159. );
  160. }
  161. Widget _buildLabel() {
  162. Widget widget;
  163. if (labelWidget != null) {
  164. widget = labelWidget!;
  165. } else {
  166. var text = Text(
  167. label!,
  168. style: const TextStyle(
  169. color: Colors.black,
  170. fontSize: 20,
  171. fontFamily: "NotoSansSC",
  172. fontFamilyFallback: const ["NotoSansSC"],
  173. ),
  174. );
  175. widget = isRequired
  176. ? RichText(
  177. text: TextSpan(
  178. text: '',
  179. children: [
  180. TextSpan(
  181. text: "* ",
  182. style: const TextStyle(color: Colors.red, fontSize: 28),
  183. ),
  184. TextSpan(
  185. text: label ?? '',
  186. style: TextStyle(
  187. fontSize: 20,
  188. color: Colors.black,
  189. fontFamily: "NotoSansSC",
  190. fontFamilyFallback: const ["NotoSansSC"],
  191. ),
  192. ),
  193. ],
  194. ),
  195. )
  196. : text;
  197. }
  198. return Container(width: labelWidth ?? 280, child: widget);
  199. }
  200. Widget? _buildContent() {
  201. if (contentWidget != null) {
  202. return contentWidget!;
  203. }
  204. if (content != null && content!.isNotEmpty) {
  205. return Expanded(
  206. child: Text(
  207. content!,
  208. textAlign: TextAlign.end,
  209. style: TextStyle(
  210. color: Colors.grey.shade700,
  211. fontSize: 20,
  212. overflow: TextOverflow.ellipsis,
  213. ),
  214. ),
  215. );
  216. }
  217. return null;
  218. }
  219. Widget _buildAction() {
  220. return endIcon ??
  221. Icon(
  222. Icons.keyboard_arrow_right,
  223. size: 32,
  224. color: Colors.grey.shade400,
  225. );
  226. }
  227. }