@ -1,3 +1,4 @@
import ' dart:async ' ;
import ' dart:developer ' ;
import ' package:car_provider_app/views/branch_management/services/duplication/sheet/approved_branches_list_sheet.dart ' ;
@ -38,6 +39,8 @@ class _MatchedServicesPageState extends State<MatchedServicesPage> {
super . initState ( ) ;
serviceVM = Provider . of < ServiceVM > ( context , listen: false ) ;
getMatchedServices ( ) ;
serviceVM . isAllSelected = false ;
setState ( ( ) { } ) ;
}
getMatchedServices ( ) {
@ -60,40 +63,44 @@ class _MatchedServicesPageState extends State<MatchedServicesPage> {
child: Column (
children: [
12. height ,
DropDownText (
title: widget . matchServicesArguments ! . oldBranchName ,
showDropDownIcon: false ,
) ,
12. height ,
GestureDetector (
onTap: ( ) {
bool newValue = ! context . read < ServiceVM > ( ) . isAllSelected ;
serviceVM . selectAllServices ( newValue ) ;
} ,
child: Row (
mainAxisAlignment: MainAxisAlignment . end ,
children: [
SizedBox (
height: 30 ,
width: 30 ,
child: Checkbox (
value: context . watch < ServiceVM > ( ) . isAllSelected ,
onChanged: ( v ) {
serviceVM . selectAllServices ( v ? ? false ) ;
} ,
) ,
) ,
LocaleKeys . selectAll . tr ( ) . toText ( fontSize: 14 ) ,
] ,
) ,
) ,
DropDownText ( title: widget . matchServicesArguments ! . oldBranchName , showDropDownIcon: false ) ,
/ / 12. height ,
/ / Consumer (
/ / builder: ( BuildContext context , ServiceVM serviceVM , Widget ? child ) {
/ / if ( serviceVM . matchedServices = = null | | serviceVM . matchedServices ! . isEmpty ) {
/ / return const SizedBox ( ) ;
/ / }
/ / return GestureDetector (
/ / onTap: ( ) {
/ / bool newValue = ! context . read < ServiceVM > ( ) . isAllSelected ;
/ / serviceVM . selectAllServices ( newValue ) ;
/ / } ,
/ / child: Row (
/ / mainAxisAlignment: MainAxisAlignment . end ,
/ / children: [
/ / SizedBox (
/ / height: 30 ,
/ / width: 30 ,
/ / child: Checkbox (
/ / value: context . watch < ServiceVM > ( ) . isAllSelected ,
/ / onChanged: ( v ) {
/ / serviceVM . selectAllServices ( v ? ? false ) ;
/ / } ,
/ / ) ,
/ / ) ,
/ / LocaleKeys . selectAll . tr ( ) . toText ( fontSize: 14 ) ,
/ / ] ,
/ / ) ,
/ / ) ;
/ / } ,
/ / ) ,
12. height ,
Expanded (
child: Consumer < ServiceVM > ( builder: ( context , ServiceVM serviceVM , _ ) {
if ( serviceVM . matchedServices = = null ) {
return const Center ( child: CircularProgressIndicator ( ) ) ;
} else if ( serviceVM . matchedServices ! . isEmpty ) {
return EmptyWidget ( text: LocaleKeys . noServicesAvailable . tr ( ) , isWrappedColumn: false ) ;
return EmptyWidget ( text: LocaleKeys . noServicesAvailable ToCopy . tr ( ) , isWrappedColumn: false ) ;
}
return ListView . separated (
itemBuilder: ( context , index ) {
@ -101,17 +108,35 @@ class _MatchedServicesPageState extends State<MatchedServicesPage> {
mainAxisAlignment: MainAxisAlignment . start ,
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
Checkbox (
value: serviceVM . matchedServices ! [ index ] . isExpandedOrSelected ,
onChanged: ( v ) {
if ( serviceVM . matchedServices ! [ index ] . serviceItems ! . isEmpty ) {
Utils . showToast ( LocaleKeys . noAvailableItems . tr ( ) ) ;
} else {
serviceVM . matchedServices ! [ index ] . isExpandedOrSelected = v ? ? false ;
serviceVM . updateServiceItem ( index , serviceVM . matchedServices ! [ index ] . isExpandedOrSelected ) ;
}
} ,
) ,
Builder ( builder: ( context ) {
int lengthSelected = serviceVM . matchedServices ! [ index ] . serviceItems ! . where ( ( c ) = > c . isUpdateOrSelected = = true ) . length ;
int totalLength = serviceVM . matchedServices ! [ index ] . serviceItems ! . length ;
if ( lengthSelected = = 0 | | lengthSelected < totalLength ) {
serviceVM . matchedServices ! [ index ] . isExpandedOrSelected = false ;
serviceVM . isAllSelected = false ;
}
return Checkbox (
value: lengthSelected = = totalLength ? true : serviceVM . matchedServices ! [ index ] . isExpandedOrSelected ,
onChanged: ( v ) {
if ( serviceVM . matchedServices ! [ index ] . serviceItems ! . isEmpty ) {
Utils . showToast ( LocaleKeys . noAvailableItems . tr ( ) ) ;
} else {
serviceVM . matchedServices ! [ index ] . isExpandedOrSelected = v ? ? false ;
serviceVM . updateServiceItem ( index , serviceVM . matchedServices ! [ index ] . isExpandedOrSelected ) ;
bool isAllChecked = true ;
for ( var service in serviceVM . matchedServices ! ) {
if ( service . isExpandedOrSelected = = false ) {
isAllChecked = false ;
break ;
}
}
serviceVM . isAllSelected = isAllChecked ;
setState ( ( ) { } ) ;
}
} ,
) ;
} ) ,
Expanded (
child: Column (
mainAxisAlignment: MainAxisAlignment . start ,
@ -120,7 +145,7 @@ class _MatchedServicesPageState extends State<MatchedServicesPage> {
serviceVM . matchedServices ! [ index ] . serviceDescription . toString ( ) . toText ( fontSize: 16 , isBold: true ) ,
" ${ serviceVM . matchedServices ! [ index ] . serviceItems ! . where ( ( c ) = > c . isUpdateOrSelected = = true ) . length } items selected out of ${ serviceVM . matchedServices ! [ index ] . serviceItems ! . length } "
. toText ( color: MyColors . lightTextColor ) ,
LocaleKeys . tapToSeeItems . t oText( color: MyColors . lightTextColor ) ,
LocaleKeys . tapToSeeItems . t r( ) . t oText( color: MyColors . lightTextColor ) ,
] ,
) ,
) ,
@ -129,6 +154,7 @@ class _MatchedServicesPageState extends State<MatchedServicesPage> {
( ) {
showMyBottomSheet (
context ,
isDismissible: false ,
child: ItemsSelectionSheet (
serviceVM . matchedServices ! [ index ] . serviceItems ? ? [ ] ,
onItemCopied: ( List < ItemData > selected ) {