From 0b9f781dd868ed2ad30de3dfb940770a18c9bdbd Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Thu, 16 Nov 2023 10:34:10 +0300 Subject: [PATCH] Hide tabs when filter isn't empty --- .../my_request/my_requests_page.dart | 86 +++++++++++-------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/lib/new_views/pages/land_page/my_request/my_requests_page.dart b/lib/new_views/pages/land_page/my_request/my_requests_page.dart index c89707eb..15827be7 100644 --- a/lib/new_views/pages/land_page/my_request/my_requests_page.dart +++ b/lib/new_views/pages/land_page/my_request/my_requests_page.dart @@ -73,6 +73,7 @@ class _MyRequestsPageState extends State { final result = await Navigator.push(context, MaterialPageRoute(builder: (context) => AllRequestsSearchPage(data: _search))); if (result != null) { _search = result; + setState(() {}); } }).expanded, 16.width, @@ -83,6 +84,7 @@ class _MyRequestsPageState extends State { final result = await Navigator.push(context, MaterialPageRoute(builder: (context) => AllRequestsFilterPage(data: _search))); if (result != null) { _search = result; + setState(() {}); } }), ], @@ -90,45 +92,61 @@ class _MyRequestsPageState extends State { ), body: Column( children: [ - SizedBox( - height: 34 + 16.0, - child: ListView.separated( - scrollDirection: Axis.horizontal, - padding: const EdgeInsets.only(top: 16, right: 16, left: 16), - itemBuilder: (cxt, index) => Container( - alignment: Alignment.center, - padding: const EdgeInsets.symmetric(horizontal: 8), - decoration: ShapeDecoration( - color: selectedRequest == index ? Color(0xFFEAF1F4) : Colors.white, - shape: RoundedRectangleBorder( - side: BorderSide(width: 1, color: selectedRequest == index ? Color(0xFF4A8DB7) : Colors.white), - borderRadius: BorderRadius.circular(7), + if (_filterIsEmpty()) + SizedBox( + height: 34 + 16.0, + child: ListView.separated( + scrollDirection: Axis.horizontal, + padding: const EdgeInsets.only(top: 16, right: 16, left: 16), + itemBuilder: (cxt, index) => Container( + alignment: Alignment.center, + padding: const EdgeInsets.symmetric(horizontal: 8), + decoration: ShapeDecoration( + color: selectedRequest == index ? Color(0xFFEAF1F4) : Colors.white, + shape: RoundedRectangleBorder( + side: BorderSide(width: 1, color: selectedRequest == index ? Color(0xFF4A8DB7) : Colors.white), + borderRadius: BorderRadius.circular(7), + ), + shadows: const [ + BoxShadow( + color: Color(0x07000000), + blurRadius: 14, + offset: Offset(0, 0), + spreadRadius: 0, + ) + ], ), - shadows: const [ - BoxShadow( - color: Color(0x07000000), - blurRadius: 14, - offset: Offset(0, 0), - spreadRadius: 0, - ) - ], - ), - child: Text(requestsList[index], style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral20 : AppColor.neutral50, height: 1)), - ).onPress(() { - if (selectedRequest != index) { - setState(() { - selectedRequest = index; - }); - _provider.getAllRequests(context, typeTransaction: selectedRequest == 0 ? null : selectedRequest); - } - }), - separatorBuilder: (cxt, index) => 8.width, - itemCount: requestsList.length), - ), + child: Text(requestsList[index], style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral20 : AppColor.neutral50, height: 1)), + ).onPress(() { + if (selectedRequest != index) { + setState(() { + selectedRequest = index; + }); + _provider.getAllRequests(context, typeTransaction: selectedRequest == 0 ? null : selectedRequest); + } + }), + separatorBuilder: (cxt, index) => 8.width, + itemCount: requestsList.length), + ), Consumer(builder: (context, snapshot, _) { return RequestItemViewList(snapshot.allRequestsAndCount?.requestsDetails ?? [], snapshot.isAllLoading); }).expanded, ], )); } + + bool _filterIsEmpty() { + if (_search == null) return true; + if ((_search.requestNumber?.value?.isNotEmpty ?? false) || + (_search.assetNo?.value?.isNotEmpty ?? false) || + (_search.assetName?.value?.isNotEmpty ?? false) || + (_search.manufacture?.value?.isNotEmpty ?? false) || + (_search.sn?.value?.isNotEmpty ?? false) || + (_search.statuses?.isNotEmpty ?? false) || + (_search.startDate != null) || + (_search.endDate != null)) { + return false; + } + return true; + } }