import 'package:flutter/material.dart'; import 'package:vitalapp/consts/styles.dart'; class VListFormCellGroup extends StatelessWidget { final List children; final double? leadingIconWidth; final String? formTitle; const VListFormCellGroup({ Key? key, required this.children, this.leadingIconWidth, this.formTitle, }) : super(key: key); @override Widget build(BuildContext context) { final divider = Divider( thickness: 1, color: Colors.grey.shade400, indent: leadingIconWidth, ); final kids = [_buildVListFromCellGroupTitle()]; for (var i = 0; i < children.length; i++) { Widget kid = children[i]; if (i > 0) { kids.add(divider); } kids.add(kid); } return Container( alignment: Alignment.center, padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20), decoration: BoxDecoration( color: Colors.white, borderRadius: GlobalStyles.borderRadius, ), child: Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: kids, ), ); } Widget _buildVListFromCellGroupTitle() { if (formTitle == null) { return const SizedBox(); } else { return Container( padding: const EdgeInsets.only(bottom: 8), child: Text( formTitle!, textAlign: TextAlign.left, style: const TextStyle( fontSize: 30, fontWeight: FontWeight.bold, ), ), ); } } } class VListFormCell extends StatelessWidget { final String? label; final Widget? labelWidget; final double? labelWidth; final String? content; final Widget? contentWidget; final VoidCallback? onTap; final double? height; final double? leadingIconWidth; final Widget? leadingIcon; final Widget? endIcon; final bool isRequired; const VListFormCell({ super.key, this.label, this.labelWidget, this.labelWidth, this.content, this.contentWidget, this.onTap, this.height, this.leadingIcon, this.endIcon, this.leadingIconWidth, this.isRequired = false, }) : assert(label != null || labelWidget != null); @override Widget build(BuildContext context) { final h = height ?? 48; final children = []; if (leadingIcon != null) { final leadingWidget = SizedBox( width: leadingIconWidth ?? h * .6, child: leadingIcon, ); children.add(leadingWidget); } children.add(_buildLabel()); children.add(Expanded(child: _buildRightPart())); return SizedBox( height: h, child: InkWell( onTap: onTap, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: children, ), ), ); } Widget _buildRightPart() { final children = []; final contentChild = _buildContent(); if (contentChild != null) { children.add(contentChild); } if (endIcon != null) { children.add( SizedBox( height: height ?? 40, child: _buildAction(), ), ); } // if (onTap != null) { // children.add( // SizedBox( // height: height ?? 40, // child: _buildAction(), // ), // ); // } else { // children.add(const SizedBox(width: 12)); // } return Row( mainAxisAlignment: MainAxisAlignment.end, mainAxisSize: MainAxisSize.max, children: children, ); } Widget _buildLabel() { Widget widget; if (labelWidget != null) { widget = labelWidget!; } else { var text = Text( label!, style: const TextStyle( color: Colors.black, fontSize: 20, fontFamily: "NotoSansSC", fontFamilyFallback: const ["NotoSansSC"], ), ); widget = isRequired ? RichText( text: TextSpan( style: TextStyle( fontFamily: "NotoSansSC", fontFamilyFallback: const ["NotoSansSC"], ), children: [ TextSpan( text: label!, style: const TextStyle(color: Colors.black, fontSize: 20), ), TextSpan( text: "*", style: const TextStyle(color: Colors.red, fontSize: 20), ), ]), ) : text; } return SizedBox(width: labelWidth ?? 280, child: widget); } Widget? _buildContent() { if (contentWidget != null) { return contentWidget!; } if (content != null && content!.isNotEmpty) { return Expanded( child: Text( content!, textAlign: TextAlign.end, style: TextStyle( color: Colors.grey.shade700, fontSize: 20, overflow: TextOverflow.ellipsis, ), ), ); } return null; } Widget _buildAction() { return endIcon ?? Icon( Icons.keyboard_arrow_right, size: 32, color: Colors.grey.shade400, ); } }