From 879e02b9745037873fbcdc836e05e408a323e3a3 Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Thu, 16 Nov 2023 19:49:58 +0300 Subject: [PATCH] Hide the null items in PPM checklist --- .../pentry/pentry_ppm_check_list_form.dart | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/lib/views/widgets/pentry/pentry_ppm_check_list_form.dart b/lib/views/widgets/pentry/pentry_ppm_check_list_form.dart index 6f3be553..a2636411 100644 --- a/lib/views/widgets/pentry/pentry_ppm_check_list_form.dart +++ b/lib/views/widgets/pentry/pentry_ppm_check_list_form.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/extensions/text_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/models/pantry/ppm_check_list.dart'; import 'package:test_sa/new_views/app_style/app_color.dart'; import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart'; @@ -21,30 +22,32 @@ class _PentryPMChecklistFormState extends State { @override Widget build(BuildContext context) { - return ListView.builder( - padding: EdgeInsets.only(top: 16.toScreenHeight), - itemCount: widget.models.length, - shrinkWrap: true, - itemBuilder: (context, index) { - final model = widget.models[index]; - return Card( - child: ExpansionTile( - shape: const Border(), - title: (model.title ?? "").heading5(context), - subtitle: "${context.translation.status} ${model.status?.name}".bodyText(context), - initiallyExpanded: index == 0, - iconColor: AppColor.neutral50, - collapsedIconColor: AppColor.neutral50, - childrenPadding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), - children: [ - AppTextFormField(labelText: context.translation.measuredValue, initialValue: model.measuredValue, enable: false), - 8.height, - AppTextFormField(labelText: context.translation.comment, initialValue: model.comment, enable: false), - 8.height, - ], - ), - ); - }, - ); + final list = widget.models?.where((element) => element.title != null)?.toList(); + return (list?.isEmpty ?? true) + ? context.translation.noDataFound.heading5(context).center + : ListView.builder( + padding: EdgeInsets.only(top: 16.toScreenHeight), + itemCount: list?.length, + shrinkWrap: true, + itemBuilder: (context, index) { + return Card( + child: ExpansionTile( + shape: const Border(), + title: (list[index].title ?? "").heading5(context), + subtitle: "${context.translation.status} ${list[index].status?.name}".bodyText(context), + initiallyExpanded: index == 0, + iconColor: AppColor.neutral50, + collapsedIconColor: AppColor.neutral50, + childrenPadding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight), + children: [ + AppTextFormField(labelText: context.translation.measuredValue, initialValue: list[index].measuredValue, enable: false), + 8.height, + AppTextFormField(labelText: context.translation.comment, initialValue: list[index].comment, enable: false), + 8.height, + ], + ), + ); + }, + ); } }