cell.dart 5.2 KB

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