123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- import 'package:flutter/material.dart';
- import 'package:vitalapp/consts/styles.dart';
- class VListFormCellGroup extends StatelessWidget {
- final List<Widget> 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 = <Widget>[_buildVListFromCellGroupTitle()];
- for (var i = 0; i < children.length; i++) {
- if (i > 0) {
- kids.add(divider);
- }
- kids.add(children[i]);
- }
- 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;
- const VListFormCell({
- super.key,
- this.label,
- this.labelWidget,
- this.labelWidth,
- this.content,
- this.contentWidget,
- this.onTap,
- this.height,
- this.leadingIcon,
- this.leadingIconWidth,
- }) : assert(label != null || labelWidget != null);
- @override
- Widget build(BuildContext context) {
- final h = height ?? 48;
- final children = <Widget>[];
- if (leadingIcon != null) {
- final leadingWidget = SizedBox(
- width: leadingIconWidth ?? h * .6,
- child: leadingIcon,
- );
- children.add(leadingWidget);
- }
- // if (isRequired ?? false) {
- // children.add(const Text(
- // '*',
- // style: TextStyle(
- // color: Colors.red,
- // fontSize: 20,
- // ),
- // ));
- // }
- 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 = <Widget>[];
- final contentChild = _buildContent();
- if (contentChild != null) {
- children.add(contentChild);
- }
- 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 {
- widget = Text(
- label!,
- style: const TextStyle(color: Colors.black, fontSize: 20),
- );
- }
- 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 Icon(
- Icons.keyboard_arrow_right,
- size: 32,
- color: Colors.grey.shade400,
- );
- }
- }
|