cell.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import 'package:flutter/material.dart';
  2. class VListFormCellGroup extends StatelessWidget {
  3. final List<Widget> children;
  4. const VListFormCellGroup({
  5. Key? key,
  6. required this.children,
  7. }) : super(key: key);
  8. @override
  9. Widget build(BuildContext context) {
  10. final divider = Divider(thickness: 1, color: Colors.grey.shade400);
  11. final kids = <Widget>[];
  12. for (var i = 0; i < children.length; i++) {
  13. if (i > 0) {
  14. kids.add(divider);
  15. }
  16. kids.add(children[i]);
  17. }
  18. return Container(
  19. alignment: Alignment.center,
  20. padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20),
  21. decoration: BoxDecoration(
  22. color: Colors.white,
  23. borderRadius: BorderRadius.circular(16),
  24. ),
  25. child: Column(
  26. mainAxisSize: MainAxisSize.min,
  27. mainAxisAlignment: MainAxisAlignment.start,
  28. children: kids,
  29. ),
  30. );
  31. }
  32. }
  33. class VListFormCell extends StatelessWidget {
  34. final String? label;
  35. final Widget? labelWidget;
  36. final String? content;
  37. final Widget? contentWidget;
  38. final VoidCallback? onTap;
  39. final double? height;
  40. const VListFormCell({
  41. super.key,
  42. this.label,
  43. this.labelWidget,
  44. this.content,
  45. this.contentWidget,
  46. this.onTap,
  47. this.height,
  48. }) : assert(label != null || labelWidget != null);
  49. @override
  50. Widget build(BuildContext context) {
  51. final children = <Widget>[];
  52. children.add(_buildLabel());
  53. children.add(SizedBox(width: 500, child: _buildRightPart()));
  54. return SizedBox(
  55. height: height ?? 40,
  56. child: InkWell(
  57. onTap: onTap,
  58. child: Row(
  59. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  60. children: children,
  61. ),
  62. ),
  63. );
  64. }
  65. Widget _buildRightPart() {
  66. final children = <Widget>[];
  67. final contentChild = _buildContent();
  68. if (contentChild != null) {
  69. children.add(contentChild);
  70. }
  71. if (onTap != null) {
  72. children.add(
  73. SizedBox(
  74. height: height ?? 40,
  75. child: _buildAction(),
  76. ),
  77. );
  78. } else {
  79. children.add(const SizedBox(width: 12));
  80. }
  81. return Row(
  82. mainAxisAlignment: MainAxisAlignment.end,
  83. mainAxisSize: MainAxisSize.max,
  84. children: children,
  85. );
  86. }
  87. Widget _buildLabel() {
  88. Widget widget;
  89. if (labelWidget != null) {
  90. widget = labelWidget!;
  91. } else {
  92. widget = Text(
  93. label!,
  94. style: const TextStyle(color: Colors.black, fontSize: 20),
  95. );
  96. }
  97. return SizedBox(width: 200, child: widget);
  98. }
  99. Widget? _buildContent() {
  100. if (contentWidget != null) {
  101. return contentWidget!;
  102. }
  103. if (content != null && content!.isNotEmpty) {
  104. return Text(
  105. content!,
  106. style: TextStyle(color: Colors.grey.shade700, fontSize: 20),
  107. );
  108. }
  109. return null;
  110. }
  111. Widget _buildAction() {
  112. return Icon(
  113. Icons.keyboard_arrow_right,
  114. size: 32,
  115. color: Colors.grey.shade400,
  116. );
  117. }
  118. }