cell.dart 4.3 KB

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