123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- 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++) {
- 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 = <Widget>[];
- 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 = <Widget>[];
- 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,
- );
- }
- }
|