From 34e3f76845ab3a3036f6f39e63ad4506fd95ed26 Mon Sep 17 00:00:00 2001 From: fhkhd Date: Sat, 20 Apr 2024 18:27:55 +0430 Subject: [PATCH] Back button of pages navigate to home --- lib/pages/CyclePages/cycle_detail_screen.dart | 74 +-- lib/pages/ItemPages/item_detail_screen.dart | 78 +-- lib/pages/LabelPages/label_detail_screen.dart | 74 +-- .../MyItemsPages/my_items_detail_screen.dart | 87 ++-- .../my_items_transfer_screen.dart | 461 +++++++++--------- .../my_packages_detail_screen.dart | 87 ++-- .../my_packages_transfer_screen.dart | 394 ++++++++------- .../PackagePages/package_detail_screen.dart | 99 ++-- lib/pages/TestPages/test_detail_screen.dart | 70 +-- 9 files changed, 770 insertions(+), 654 deletions(-) diff --git a/lib/pages/CyclePages/cycle_detail_screen.dart b/lib/pages/CyclePages/cycle_detail_screen.dart index 97852a4..e9b5acb 100755 --- a/lib/pages/CyclePages/cycle_detail_screen.dart +++ b/lib/pages/CyclePages/cycle_detail_screen.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import '../../config/routes.dart'; import '../../models/cycles_models.dart'; import '../../providers/connectivity.dart'; import '../../providers/cycles.dart'; @@ -21,6 +22,7 @@ class _CycleDetailScreenState extends State { bool isInit = true; bool isEmpty = false; CycleDetailObject? datas; + @override void didChangeDependencies() async { if (isInit) { @@ -50,39 +52,51 @@ class _CycleDetailScreenState extends State { // final double _pixelRatio = (_media.size.height / _media.size.width * 7 / 5); final double _devicewidth = _media.size.width; final double _deviceBlockSize = _devicewidth / 100; - return SafeArea( - child: Scaffold( - appBar: AppBar( - titleSpacing: -10, - title: Text('Cycles', style: TextStyle(color: Colors.white,),), - backgroundColor: Colors.black, - leading: IconButton( - icon: Icon( - Icons.keyboard_arrow_left, - color: Colors.white, - size: 35, + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + Navigator.of(context).pushNamed(Routes.homePage); + }, + child: SafeArea( + child: Scaffold( + appBar: AppBar( + titleSpacing: -10, + title: Text( + 'Cycles', + style: TextStyle( + color: Colors.white, + ), + ), + backgroundColor: Colors.black, + leading: IconButton( + icon: Icon( + Icons.keyboard_arrow_left, + color: Colors.white, + size: 35, + ), + onPressed: () => Navigator.of(context).pop(), ), - onPressed: () => Navigator.of(context).pop(), ), + body: Consumer(builder: (ct, connection, _) { + return connection.conStatus != 'offline' + ? isInit + ? Center( + child: CircularProgressIndicator( + color: Colors.black, + ), + ) + : isEmpty + ? Center( + child: Text('This Cycle doesnt exists!'), + ) + : CycleDetailsDataBox( + datas: datas!, + deviceBlockSize: _deviceBlockSize, + ) + : ConnectionErrorBox(); + }), ), - body: Consumer(builder: (ct, connection, _) { - return connection.conStatus != 'offline' - ? isInit - ? Center( - child: CircularProgressIndicator( - color: Colors.black, - ), - ) - : isEmpty - ? Center( - child: Text('This Cycle doesnt exists!'), - ) - : CycleDetailsDataBox( - datas: datas!, - deviceBlockSize: _deviceBlockSize, - ) - : ConnectionErrorBox(); - }), ), ); } diff --git a/lib/pages/ItemPages/item_detail_screen.dart b/lib/pages/ItemPages/item_detail_screen.dart index 1bfec5d..956eea8 100755 --- a/lib/pages/ItemPages/item_detail_screen.dart +++ b/lib/pages/ItemPages/item_detail_screen.dart @@ -4,6 +4,7 @@ import 'package:cssd/widgets/ItemScreens/Details/item_detail_box.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import '../../config/routes.dart'; import '../../providers/connectivity.dart'; import '../../widgets/Global/internet_error.dart'; @@ -22,6 +23,7 @@ class _ItemDetailScreenState extends State { bool isInit = true; bool isEmpty = false; ItemDetailObject? datas; + @override void didChangeDependencies() async { if (isInit) { @@ -50,40 +52,52 @@ class _ItemDetailScreenState extends State { final _media = MediaQuery.of(context); final double _devicewidth = _media.size.width; final double _deviceBlockSize = _devicewidth / 100; - return SafeArea( - child: Scaffold( - appBar: AppBar( - titleSpacing: -10, - title: Text('Items', style: TextStyle(color: Colors.white,),), - backgroundColor: Colors.black, - leading: IconButton( - icon: Icon( - Icons.keyboard_arrow_left, - color: Colors.white, - size: 35, + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + Navigator.of(context).pushNamed(Routes.homePage); + }, + child: SafeArea( + child: Scaffold( + appBar: AppBar( + titleSpacing: -10, + title: Text( + 'Items', + style: TextStyle( + color: Colors.white, + ), + ), + backgroundColor: Colors.black, + leading: IconButton( + icon: Icon( + Icons.keyboard_arrow_left, + color: Colors.white, + size: 35, + ), + onPressed: () => Navigator.of(context).pop(), ), - onPressed: () => Navigator.of(context).pop(), ), - ), - body: Consumer( - builder: (ct, connection, _) { - return connection.conStatus != 'offline' - ? isInit - ? Center( - child: CircularProgressIndicator( - color: Colors.black, - ), - ) - : isEmpty - ? Center( - child: Text('This Item does\'nt exists!'), - ) - : ItemDetailsDataBox( - datas: datas!, - deviceBlockSize: _deviceBlockSize, - ) - : ConnectionErrorBox(); - }, + body: Consumer( + builder: (ct, connection, _) { + return connection.conStatus != 'offline' + ? isInit + ? Center( + child: CircularProgressIndicator( + color: Colors.black, + ), + ) + : isEmpty + ? Center( + child: Text('This Item does\'nt exists!'), + ) + : ItemDetailsDataBox( + datas: datas!, + deviceBlockSize: _deviceBlockSize, + ) + : ConnectionErrorBox(); + }, + ), ), ), ); diff --git a/lib/pages/LabelPages/label_detail_screen.dart b/lib/pages/LabelPages/label_detail_screen.dart index 73f01f3..c782965 100755 --- a/lib/pages/LabelPages/label_detail_screen.dart +++ b/lib/pages/LabelPages/label_detail_screen.dart @@ -1,3 +1,4 @@ +import '../../config/routes.dart'; import '../../models/label_models.dart'; import '../../providers/connectivity.dart'; import '../../providers/labels.dart'; @@ -20,6 +21,7 @@ class _LabelDetailScreenState extends State { bool isEmpty = false; bool isInit = true; LabelDetailsObject? datas; + @override void didChangeDependencies() async { if (isInit) { @@ -50,39 +52,51 @@ class _LabelDetailScreenState extends State { // final double _pixelRatio = (_media.size.height / _media.size.width * 7 / 5); final double _devicewidth = _media.size.width; final double _deviceBlockSize = _devicewidth / 100; - return SafeArea( - child: Scaffold( - appBar: AppBar( - titleSpacing: -10, - title: Text('Labels', style: TextStyle(color: Colors.white,),), - backgroundColor: Colors.black, - leading: IconButton( - icon: Icon( - Icons.keyboard_arrow_left, - color: Colors.white, - size: 35, + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + Navigator.of(context).pushNamed(Routes.homePage); + }, + child: SafeArea( + child: Scaffold( + appBar: AppBar( + titleSpacing: -10, + title: Text( + 'Labels', + style: TextStyle( + color: Colors.white, + ), + ), + backgroundColor: Colors.black, + leading: IconButton( + icon: Icon( + Icons.keyboard_arrow_left, + color: Colors.white, + size: 35, + ), + onPressed: () => Navigator.of(context).pop(), ), - onPressed: () => Navigator.of(context).pop(), ), + body: Consumer(builder: (ct, connection, _) { + return connection.conStatus != 'offline' + ? isInit + ? Center( + child: CircularProgressIndicator( + color: Colors.black, + ), + ) + : isEmpty + ? Center( + child: Text('This Label dos\'nt exists!'), + ) + : LabelDetailsDataBox( + datas: datas!, + deviceBlockSize: _deviceBlockSize, + ) + : ConnectionErrorBox(); + }), ), - body: Consumer(builder: (ct, connection, _) { - return connection.conStatus != 'offline' - ? isInit - ? Center( - child: CircularProgressIndicator( - color: Colors.black, - ), - ) - : isEmpty - ? Center( - child: Text('This Label dos\'nt exists!'), - ) - : LabelDetailsDataBox( - datas: datas!, - deviceBlockSize: _deviceBlockSize, - ) - : ConnectionErrorBox(); - }), ), ); } diff --git a/lib/pages/MyItemsPages/my_items_detail_screen.dart b/lib/pages/MyItemsPages/my_items_detail_screen.dart index c8d28bb..f843ae3 100755 --- a/lib/pages/MyItemsPages/my_items_detail_screen.dart +++ b/lib/pages/MyItemsPages/my_items_detail_screen.dart @@ -23,6 +23,7 @@ class _MyItemsDetailScreenState extends State { bool isInit = true; bool isEmpty = false; ItemDetailObject? datas; + @override void didChangeDependencies() async { if (isInit) { @@ -51,45 +52,57 @@ class _MyItemsDetailScreenState extends State { final _media = MediaQuery.of(context); final double _devicewidth = _media.size.width; final double _deviceBlockSize = _devicewidth / 100; - return SafeArea( - child: Scaffold( - appBar: AppBar( - titleSpacing: -10, - title: Text('My Items', style: TextStyle(color: Colors.white,),), - backgroundColor: Colors.black, - leading: IconButton( - icon: Icon( - Icons.keyboard_arrow_left, - color: Colors.white, - size: 35, + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + Navigator.of(context).pushNamed(Routes.homePage); + }, + child: SafeArea( + child: Scaffold( + appBar: AppBar( + titleSpacing: -10, + title: Text( + 'My Items', + style: TextStyle( + color: Colors.white, + ), + ), + backgroundColor: Colors.black, + leading: IconButton( + icon: Icon( + Icons.keyboard_arrow_left, + color: Colors.white, + size: 35, + ), + onPressed: () => Navigator.of(context).pop(), ), - onPressed: () => Navigator.of(context).pop(), ), - ), - body: Consumer( - builder: (ct, connection, _) { - return connection.conStatus != 'offline' - ? isInit - ? Center( - child: CircularProgressIndicator( - color: Colors.black, - ), - ) - : isEmpty - ? Center( - child: Text('This Item does\'nt exists!'), - ) - : MyItemsDetailsDataBox( - datas: datas!, - deviceBlockSize: _deviceBlockSize, - push: () { - Navigator.pushNamed( - context, Routes.itemsTransferScreen, - arguments: datas); - }, - ) - : ConnectionErrorBox(); - }, + body: Consumer( + builder: (ct, connection, _) { + return connection.conStatus != 'offline' + ? isInit + ? Center( + child: CircularProgressIndicator( + color: Colors.black, + ), + ) + : isEmpty + ? Center( + child: Text('This Item does\'nt exists!'), + ) + : MyItemsDetailsDataBox( + datas: datas!, + deviceBlockSize: _deviceBlockSize, + push: () { + Navigator.pushNamed( + context, Routes.itemsTransferScreen, + arguments: datas); + }, + ) + : ConnectionErrorBox(); + }, + ), ), ), ); diff --git a/lib/pages/MyItemsPages/my_items_transfer_screen.dart b/lib/pages/MyItemsPages/my_items_transfer_screen.dart index 13bd214..a10f7b0 100755 --- a/lib/pages/MyItemsPages/my_items_transfer_screen.dart +++ b/lib/pages/MyItemsPages/my_items_transfer_screen.dart @@ -14,7 +14,6 @@ import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:provider/provider.dart'; - class ItemsTransferScreen extends StatefulWidget { final bool? isAdmin; final ItemDetailObject? items; @@ -80,240 +79,250 @@ class _ItemsTransferScreenState extends State { final _media = MediaQuery.of(context); final double _deviceWidth = _media.size.width; final double _deviceBlockSize = _deviceWidth / 100; - return SafeArea( - child: GestureDetector( - onTap: () { - FocusManager.instance.primaryFocus?.unfocus(); - }, - child: Scaffold( - appBar: AppBar( - titleSpacing: -10, - title: Text( - 'Item Details', - style: TextStyle( - color: Colors.white, + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + Navigator.of(context).pushNamed(Routes.homePage); + }, + child: SafeArea( + child: GestureDetector( + onTap: () { + FocusManager.instance.primaryFocus?.unfocus(); + }, + child: Scaffold( + appBar: AppBar( + titleSpacing: -10, + title: Text( + 'Item Details', + style: TextStyle( + color: Colors.white, + ), + ), + backgroundColor: Colors.black, + leading: IconButton( + icon: Icon( + Icons.keyboard_arrow_left, + color: Colors.white, + size: 35, + ), + onPressed: () => Navigator.of(context).pop(), ), ), - backgroundColor: Colors.black, - leading: IconButton( - icon: Icon( - Icons.keyboard_arrow_left, - color: Colors.white, - size: 35, - ), - onPressed: () => Navigator.of(context).pop(), - ), - ), - body: Consumer( - builder: (ct, connection, _) { - return connection.conStatus != 'offline' - ? Padding( - padding: EdgeInsets.only( - top: 20, - right: 20, - bottom: 40, - left: 20, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ResultBanner( - deviceBlockSize: _deviceBlockSize, - text: 'Transfer to', - hasFilterObject: false, - push: Routes.myItemsFilterScreen, - ), - SizedBox( - height: 20.0, - ), - ResultSearchBox( - searchCTRL: searchCTRL, - text: 'user', - text2: 'name or ID', - deviceBlockSize: _deviceBlockSize, - textInputType: TextInputType.visiblePassword, - onChanged: (value) { - Provider.of(context, listen: false) - .searchUsers(value); - }, - ), - SizedBox( - height: 20, - ), - Expanded( - child: Consumer( - builder: (context, userResults, _) { - return userResults.isLoading - ? Center( - child: CircularProgressIndicator( - color: Colors.black, - ), - ) - : userResults.usersBox?.length != null - ? ListView.builder( - controller: sc, - itemBuilder: (context, index) { - return TransferDataBox( - deviceBlockSize: - _deviceBlockSize, - user: userResults - .usersBox?[index], - clickColor: kDarkBlue, - isClicked: userResults - .selectedUserIndex == - index, - onTap: (userId) { - Provider.of( - context, - listen: false, - ).selectUser(index); - print(userId); - Provider.of( - context, - listen: false) - .saveUserId = userId; - Provider.of( - context, - listen: false) - .selectedUserForItems = - userResults - .usersBox?[index]; - }, - ); - }, - itemCount: - userResults.usersBox?.length, - shrinkWrap: true, - ) - : Container( - child: Center( - child: Text( - "There is no user to show."), - ), - ); + body: Consumer( + builder: (ct, connection, _) { + return connection.conStatus != 'offline' + ? Padding( + padding: EdgeInsets.only( + top: 20, + right: 20, + bottom: 40, + left: 20, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ResultBanner( + deviceBlockSize: _deviceBlockSize, + text: 'Transfer to', + hasFilterObject: false, + push: Routes.myItemsFilterScreen, + ), + SizedBox( + height: 20.0, + ), + ResultSearchBox( + searchCTRL: searchCTRL, + text: 'user', + text2: 'name or ID', + deviceBlockSize: _deviceBlockSize, + textInputType: TextInputType.visiblePassword, + onChanged: (value) { + Provider.of(context, + listen: false) + .searchUsers(value); }, ), - ), - TransferDestroyButton( - deviceBlockSize: _deviceBlockSize, - firstColor: kDarkBlue, - secondColor: kDarkBlueSub, - onTap: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text( - 'Are you sure to transfer this Item?', - style: TextStyle( - fontSize: 4 * _deviceBlockSize, - ), - ), - content: SizedBox( - width: _deviceBlockSize, - height: 320, - child: Column( - children: [ - Text( - 'By approving, your item will be transferred the specified user. It can be undone unless the user reject the transfer.', - style: TextStyle( - fontSize: 3 * _deviceBlockSize, - ), + SizedBox( + height: 20, + ), + Expanded( + child: Consumer( + builder: (context, userResults, _) { + return userResults.isLoading + ? Center( + child: CircularProgressIndicator( + color: Colors.black, ), - SizedBox( - height: 10.0, - ), - ItemCard(_deviceBlockSize, itemData!), - SizedBox( - height: 5.0, - ), - Row( - children: [ - Spacer(), - Text('To'), - SizedBox( - width: 5.0, - ), - TransferDataBox( - deviceBlockSize: - _deviceBlockSize, - user: + ) + : userResults.usersBox?.length != null + ? ListView.builder( + controller: sc, + itemBuilder: (context, index) { + return TransferDataBox( + deviceBlockSize: + _deviceBlockSize, + user: userResults + .usersBox?[index], + clickColor: kDarkBlue, + isClicked: userResults + .selectedUserIndex == + index, + onTap: (userId) { + Provider.of( + context, + listen: false, + ).selectUser(index); + print(userId); Provider.of( - context) - .selectedUserForItems, - ) - ], - ), - SizedBox( - height: 20.0, - ), - Consumer( - builder: - (context, myItemProvider, _) { - return TransferDestroyButton( - deviceBlockSize: - _deviceBlockSize, - firstColor: kDarkBlue, - secondColor: kDarkBlueSub, - onTap: () async { - myItemProvider - .setLoadingButton(); - await Provider.of< - MyItemProvider>( - context, - listen: false, - ).transferItems( - itemData!.id, - await Provider.of< - UsersProvider>( context, listen: false) - .saveUserId!, - ); - Navigator.of(context).pop(); - Navigator.of(context).pop(); - Navigator.of(context).pop(); - myItemProvider - .resetLoadingButton(); - Fluttertoast.showToast( - msg: - "The item is transferred.", - toastLength: - Toast.LENGTH_SHORT, - gravity: - ToastGravity.BOTTOM, - ); - }, - text: 'Transfer', - isLoadingButton: myItemProvider - .isloadingButton, - ); - }, - ), - SizedBox( - height: 5.0, - ), - CancelTransferButton( - deviceBlockSize: _deviceBlockSize, - color: kPink, - onTap: () { - Navigator.pop(context); - }, - ), - ], - ), - ), - ); + .saveUserId = userId; + Provider.of( + context, + listen: false) + .selectedUserForItems = + userResults + .usersBox?[index]; + }, + ); + }, + itemCount: + userResults.usersBox?.length, + shrinkWrap: true, + ) + : Container( + child: Center( + child: Text( + "There is no user to show."), + ), + ); }, - ); - }, - text: 'Transfer', - ), - ], - ), - ) - : ConnectionErrorBox(); - }, + ), + ), + TransferDestroyButton( + deviceBlockSize: _deviceBlockSize, + firstColor: kDarkBlue, + secondColor: kDarkBlueSub, + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you sure to transfer this Item?', + style: TextStyle( + fontSize: 4 * _deviceBlockSize, + ), + ), + content: SizedBox( + width: _deviceBlockSize, + height: 320, + child: Column( + children: [ + Text( + 'By approving, your item will be transferred the specified user. It can be undone unless the user reject the transfer.', + style: TextStyle( + fontSize: 3 * _deviceBlockSize, + ), + ), + SizedBox( + height: 10.0, + ), + ItemCard( + _deviceBlockSize, itemData!), + SizedBox( + height: 5.0, + ), + Row( + children: [ + Spacer(), + Text('To'), + SizedBox( + width: 5.0, + ), + TransferDataBox( + deviceBlockSize: + _deviceBlockSize, + user: Provider.of< + UsersProvider>( + context) + .selectedUserForItems, + ) + ], + ), + SizedBox( + height: 20.0, + ), + Consumer( + builder: + (context, myItemProvider, _) { + return TransferDestroyButton( + deviceBlockSize: + _deviceBlockSize, + firstColor: kDarkBlue, + secondColor: kDarkBlueSub, + onTap: () async { + myItemProvider + .setLoadingButton(); + await Provider.of< + MyItemProvider>( + context, + listen: false, + ).transferItems( + itemData!.id, + await Provider.of< + UsersProvider>( + context, + listen: false) + .saveUserId!, + ); + Navigator.of(context).pop(); + Navigator.of(context).pop(); + Navigator.of(context).pop(); + myItemProvider + .resetLoadingButton(); + Fluttertoast.showToast( + msg: + "The item is transferred.", + toastLength: + Toast.LENGTH_SHORT, + gravity: + ToastGravity.BOTTOM, + ); + }, + text: 'Transfer', + isLoadingButton: + myItemProvider + .isloadingButton, + ); + }, + ), + SizedBox( + height: 5.0, + ), + CancelTransferButton( + deviceBlockSize: _deviceBlockSize, + color: kPink, + onTap: () { + Navigator.pop(context); + }, + ), + ], + ), + ), + ); + }, + ); + }, + text: 'Transfer', + ), + ], + ), + ) + : ConnectionErrorBox(); + }, + ), ), ), ), diff --git a/lib/pages/MyPackagesPages/my_packages_detail_screen.dart b/lib/pages/MyPackagesPages/my_packages_detail_screen.dart index 1658aa4..182e307 100755 --- a/lib/pages/MyPackagesPages/my_packages_detail_screen.dart +++ b/lib/pages/MyPackagesPages/my_packages_detail_screen.dart @@ -23,6 +23,7 @@ class _MyPackagesDetailScreenState extends State { bool isInit = true; bool isEmpty = false; PackageDetailObject? datas; + @override void didChangeDependencies() async { if (isInit) { @@ -51,45 +52,57 @@ class _MyPackagesDetailScreenState extends State { final _media = MediaQuery.of(context); final double _deviceWidth = _media.size.width; final double _deviceBlockSize = _deviceWidth / 100; - return SafeArea( - child: Scaffold( - appBar: AppBar( - titleSpacing: -10, - title: Text('My Packages', style: TextStyle(color: Colors.white,),), - backgroundColor: Colors.black, - leading: IconButton( - icon: Icon( - Icons.keyboard_arrow_left, - color: Colors.white, - size: 35, + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + Navigator.of(context).pushNamed(Routes.homePage); + }, + child: SafeArea( + child: Scaffold( + appBar: AppBar( + titleSpacing: -10, + title: Text( + 'My Packages', + style: TextStyle( + color: Colors.white, + ), + ), + backgroundColor: Colors.black, + leading: IconButton( + icon: Icon( + Icons.keyboard_arrow_left, + color: Colors.white, + size: 35, + ), + onPressed: () => Navigator.of(context).pop(), ), - onPressed: () => Navigator.of(context).pop(), ), - ), - body: Consumer( - builder: (ct, connection, _) { - return connection.conStatus != 'offline' - ? isInit - ? Center( - child: CircularProgressIndicator( - color: Colors.black, - ), - ) - : isEmpty - ? Center( - child: Text('This Package does\'nt exists!'), - ) - : MyPackageDetailsDataBox( - datas: datas!, - deviceBlockSize: _deviceBlockSize, - push: () { - Navigator.pushNamed( - context, Routes.packagesTransferScreen, - arguments: datas); - }, - ) - : ConnectionErrorBox(); - }, + body: Consumer( + builder: (ct, connection, _) { + return connection.conStatus != 'offline' + ? isInit + ? Center( + child: CircularProgressIndicator( + color: Colors.black, + ), + ) + : isEmpty + ? Center( + child: Text('This Package does\'nt exists!'), + ) + : MyPackageDetailsDataBox( + datas: datas!, + deviceBlockSize: _deviceBlockSize, + push: () { + Navigator.pushNamed( + context, Routes.packagesTransferScreen, + arguments: datas); + }, + ) + : ConnectionErrorBox(); + }, + ), ), ), ); diff --git a/lib/pages/MyPackagesPages/my_packages_transfer_screen.dart b/lib/pages/MyPackagesPages/my_packages_transfer_screen.dart index 0c2c522..736d62b 100755 --- a/lib/pages/MyPackagesPages/my_packages_transfer_screen.dart +++ b/lib/pages/MyPackagesPages/my_packages_transfer_screen.dart @@ -16,6 +16,7 @@ import 'package:provider/provider.dart'; class PackageTransferScreen extends StatefulWidget { final bool? isAdmin; final PackageDetailObject? packages; + const PackageTransferScreen({ super.key, this.isAdmin, @@ -73,203 +74,220 @@ class _PackageTransferScreenState extends State { final _media = MediaQuery.of(context); final double _deviceWidth = _media.size.width; final double _deviceBlockSize = _deviceWidth / 100; - return SafeArea( - child: GestureDetector( - onTap: () { - FocusManager.instance.primaryFocus?.unfocus(); - }, - child: Scaffold( - appBar: AppBar( - titleSpacing: -10, - title: Text('Package Details', style: TextStyle(color: Colors.white,),), - backgroundColor: Colors.black, - leading: IconButton( - icon: Icon( - Icons.keyboard_arrow_left, - color: Colors.white, - size: 35, + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + Navigator.of(context).pushNamed(Routes.homePage); + }, + child: SafeArea( + child: GestureDetector( + onTap: () { + FocusManager.instance.primaryFocus?.unfocus(); + }, + child: Scaffold( + appBar: AppBar( + titleSpacing: -10, + title: Text( + 'Package Details', + style: TextStyle( + color: Colors.white, + ), + ), + backgroundColor: Colors.black, + leading: IconButton( + icon: Icon( + Icons.keyboard_arrow_left, + color: Colors.white, + size: 35, + ), + onPressed: () => Navigator.of(context).pop(), ), - onPressed: () => Navigator.of(context).pop(), ), - ), - body: Consumer( - builder: (ct, connection, _) { - return connection.conStatus != 'offline' - ? Padding( - padding: EdgeInsets.only( - top: 20, - right: 20, - bottom: 40, - left: 20, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ResultBanner( - deviceBlockSize: _deviceBlockSize, - text: 'Transfer to', - hasFilterObject: false, - push: Routes.myItemsFilterScreen, - ), - SizedBox( - height: 20.0, - ), - ResultSearchBox( - searchCTRL: searchCTRL, - text: 'user', - text2: 'name or ID', - deviceBlockSize: _deviceBlockSize, - textInputType: TextInputType.visiblePassword, - onChanged: (value) { - Provider.of(context, listen: false) - .searchUsers(value); - }, - ), - SizedBox( - height: 20, - ), - Expanded( - child: Consumer( - builder: (context, userResults, _) { - return userResults.isLoading - ? Center( - child: CircularProgressIndicator( - color: Colors.black, - ), - ) - : ListView.builder( - controller: sc, - itemBuilder: (context, index) { - return TransferDataBox( - deviceBlockSize: _deviceBlockSize, - user: userResults.usersBox?[index], - clickColor: kDarkPurple, - isClicked: - userResults.selectedUserIndex == - index, - onTap: (userId) { - Provider.of( - context, - listen: false, - ).selectUser(index); - print(userId); - Provider.of( - context, - listen: false) - .saveUserId = userId; - Provider.of( - context, - listen: false) - .selectedUserForPackages = - userResults.usersBox?[index]; - }, - ); - }, - itemCount: userResults.usersBox?.length, - shrinkWrap: true, - ); + body: Consumer( + builder: (ct, connection, _) { + return connection.conStatus != 'offline' + ? Padding( + padding: EdgeInsets.only( + top: 20, + right: 20, + bottom: 40, + left: 20, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ResultBanner( + deviceBlockSize: _deviceBlockSize, + text: 'Transfer to', + hasFilterObject: false, + push: Routes.myItemsFilterScreen, + ), + SizedBox( + height: 20.0, + ), + ResultSearchBox( + searchCTRL: searchCTRL, + text: 'user', + text2: 'name or ID', + deviceBlockSize: _deviceBlockSize, + textInputType: TextInputType.visiblePassword, + onChanged: (value) { + Provider.of(context, + listen: false) + .searchUsers(value); }, ), - ), - TransferDestroyButton( - deviceBlockSize: _deviceBlockSize, - firstColor: kDarkPurple, - secondColor: kDarkPurpleSub, - onTap: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text( - 'Are you sure to transfer this Package?', - style: TextStyle( - fontSize: 4 * _deviceBlockSize, - ), - ), - content: SizedBox( - width: _deviceBlockSize, - height: 300, - child: Column( - children: [ - Text( - 'By approving, all items in your package will be transferred the specified user. it can be undone unless the user reject the transfer.', - style: TextStyle( - fontSize: 3 * _deviceBlockSize, - ), + SizedBox( + height: 20, + ), + Expanded( + child: Consumer( + builder: (context, userResults, _) { + return userResults.isLoading + ? Center( + child: CircularProgressIndicator( + color: Colors.black, ), - SizedBox( - height: 10.0, - ), - PackageCard( - _deviceBlockSize, packageData!), - SizedBox( - height: 5.0, - ), - Row( - children: [ - Spacer(), - Text('To'), - SizedBox( - width: 5.0, - ), - TransferDataBox( - deviceBlockSize: - _deviceBlockSize, - user: Provider.of< - UsersProvider>(context) - .selectedUserForPackages, - ) - ], - ), - SizedBox( - height: 20.0, - ), - TransferDestroyButton( - deviceBlockSize: _deviceBlockSize, - firstColor: kDarkPurple, - secondColor: kDarkPurpleSub, - onTap: () { - Provider.of( - context, - listen: false, - ).transferPackage( - packageData!.id, + ) + : ListView.builder( + controller: sc, + itemBuilder: (context, index) { + return TransferDataBox( + deviceBlockSize: _deviceBlockSize, + user: + userResults.usersBox?[index], + clickColor: kDarkPurple, + isClicked: userResults + .selectedUserIndex == + index, + onTap: (userId) { + Provider.of( + context, + listen: false, + ).selectUser(index); + print(userId); Provider.of( context, listen: false) - .saveUserId!, - ); - Navigator.of(context).pop(); - Navigator.of(context) - .popAndPushNamed(Routes - .myPackagesResultScreen); - }, - text: 'Transfer', - ), - SizedBox( - height: 5.0, - ), - CancelTransferButton( - deviceBlockSize: _deviceBlockSize, - color: kPink, - onTap: () { - Navigator.pop(context); - }, - ), - ], - ), - ), - ); + .saveUserId = userId; + Provider.of( + context, + listen: false) + .selectedUserForPackages = + userResults + .usersBox?[index]; + }, + ); + }, + itemCount: + userResults.usersBox?.length, + shrinkWrap: true, + ); }, - ); - }, - text: 'Transfer', - ), - ], - ), - ) - : ConnectionErrorBox(); - }, + ), + ), + TransferDestroyButton( + deviceBlockSize: _deviceBlockSize, + firstColor: kDarkPurple, + secondColor: kDarkPurpleSub, + onTap: () { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text( + 'Are you sure to transfer this Package?', + style: TextStyle( + fontSize: 4 * _deviceBlockSize, + ), + ), + content: SizedBox( + width: _deviceBlockSize, + height: 300, + child: Column( + children: [ + Text( + 'By approving, all items in your package will be transferred the specified user. it can be undone unless the user reject the transfer.', + style: TextStyle( + fontSize: 3 * _deviceBlockSize, + ), + ), + SizedBox( + height: 10.0, + ), + PackageCard( + _deviceBlockSize, packageData!), + SizedBox( + height: 5.0, + ), + Row( + children: [ + Spacer(), + Text('To'), + SizedBox( + width: 5.0, + ), + TransferDataBox( + deviceBlockSize: + _deviceBlockSize, + user: Provider.of< + UsersProvider>( + context) + .selectedUserForPackages, + ) + ], + ), + SizedBox( + height: 20.0, + ), + TransferDestroyButton( + deviceBlockSize: _deviceBlockSize, + firstColor: kDarkPurple, + secondColor: kDarkPurpleSub, + onTap: () { + Provider.of( + context, + listen: false, + ).transferPackage( + packageData!.id, + Provider.of( + context, + listen: false) + .saveUserId!, + ); + Navigator.of(context).pop(); + Navigator.of(context) + .popAndPushNamed(Routes + .myPackagesResultScreen); + }, + text: 'Transfer', + ), + SizedBox( + height: 5.0, + ), + CancelTransferButton( + deviceBlockSize: _deviceBlockSize, + color: kPink, + onTap: () { + Navigator.pop(context); + }, + ), + ], + ), + ), + ); + }, + ); + }, + text: 'Transfer', + ), + ], + ), + ) + : ConnectionErrorBox(); + }, + ), ), ), ), diff --git a/lib/pages/PackagePages/package_detail_screen.dart b/lib/pages/PackagePages/package_detail_screen.dart index 7194a90..482c76a 100755 --- a/lib/pages/PackagePages/package_detail_screen.dart +++ b/lib/pages/PackagePages/package_detail_screen.dart @@ -47,56 +47,63 @@ class _PackageDetailScreenState extends State { final _media = MediaQuery.of(context); final double _devicewidth = _media.size.width; final double _deviceBlockSize = _devicewidth / 100; - return SafeArea( - child: Scaffold( - appBar: AppBar( - titleSpacing: -10, - title: Text( - 'Packages', - style: TextStyle( - color: Colors.white, + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + Navigator.of(context).pushNamed(Routes.homePage); + }, + child: SafeArea( + child: Scaffold( + appBar: AppBar( + titleSpacing: -10, + title: Text( + 'Packages', + style: TextStyle( + color: Colors.white, + ), + ), + backgroundColor: Colors.black, + leading: IconButton( + icon: Icon( + Icons.keyboard_arrow_left, + color: Colors.white, + size: 35, + ), + onPressed: () => Navigator.of(context).pop(), ), ), - backgroundColor: Colors.black, - leading: IconButton( - icon: Icon( - Icons.keyboard_arrow_left, - color: Colors.white, - size: 35, - ), - onPressed: () => Navigator.of(context).pop(), + body: Consumer( + builder: (ct, connection, _) { + return connection.conStatus != 'offline' + ? isInit + ? Center( + child: CircularProgressIndicator( + color: Colors.black, + ), + ) + : isEmpty + ? Center( + child: Text('This Package does\'nt exists!'), + ) + : PackageDetailsDataBox( + datas: datas!, + deviceBlockSize: _deviceBlockSize, + goToAddLabelPage: () { + Navigator.pushNamed( + context, + Routes.labelAddScreen, + arguments: { + "id": datas!.id, + "name": datas!.name + }, + ); + }, + ) + : ConnectionErrorBox(); + }, ), ), - body: Consumer( - builder: (ct, connection, _) { - return connection.conStatus != 'offline' - ? isInit - ? Center( - child: CircularProgressIndicator( - color: Colors.black, - ), - ) - : isEmpty - ? Center( - child: Text('This Package does\'nt exists!'), - ) - : PackageDetailsDataBox( - datas: datas!, - deviceBlockSize: _deviceBlockSize, - goToAddLabelPage: () { - Navigator.pushNamed( - context, - Routes.labelAddScreen, - arguments: { - "id": datas!.id, - "name": datas!.name - }, - ); - }, - ) - : ConnectionErrorBox(); - }, - ), ), ); } diff --git a/lib/pages/TestPages/test_detail_screen.dart b/lib/pages/TestPages/test_detail_screen.dart index 80e23f5..957f614 100755 --- a/lib/pages/TestPages/test_detail_screen.dart +++ b/lib/pages/TestPages/test_detail_screen.dart @@ -1,3 +1,4 @@ +import '../../config/routes.dart'; import '../../providers/connectivity.dart'; import '../../providers/test_results.dart'; import '../../widgets/Global/internet_error.dart'; @@ -18,6 +19,7 @@ class TestDetailsScreen extends StatefulWidget { class _TestDetailsScreenState extends State { bool isInit = true; Map? datas; + @override void didChangeDependencies() async { if (isInit) { @@ -42,36 +44,48 @@ class _TestDetailsScreenState extends State { final double _devicewidth = _media.size.width; final double _deviceBlockSize = _devicewidth / 100; // print(datas); - return SafeArea( - child: Scaffold( - appBar: AppBar( - titleSpacing: -10, - title: Text('Test Results', style: TextStyle(color: Colors.white,),), - backgroundColor: Colors.black, - leading: IconButton( - icon: Icon( - Icons.keyboard_arrow_left, - color: Colors.white, - size: 35, + return PopScope( + canPop: false, + onPopInvoked: (didPop) { + if (didPop) return; + Navigator.of(context).pushNamed(Routes.homePage); + }, + child: SafeArea( + child: Scaffold( + appBar: AppBar( + titleSpacing: -10, + title: Text( + 'Test Results', + style: TextStyle( + color: Colors.white, + ), + ), + backgroundColor: Colors.black, + leading: IconButton( + icon: Icon( + Icons.keyboard_arrow_left, + color: Colors.white, + size: 35, + ), + onPressed: () => Navigator.of(context).pop(), ), - onPressed: () => Navigator.of(context).pop(), ), - ), - body: Consumer( - builder: (ct, connection, _) { - return connection.conStatus != 'offline' - ? isInit - ? Center( - child: CircularProgressIndicator( - color: Colors.black, - ), - ) - : DatasBox( - datas: datas!, - deviceBlockSize: _deviceBlockSize, - ) - : ConnectionErrorBox(); - }, + body: Consumer( + builder: (ct, connection, _) { + return connection.conStatus != 'offline' + ? isInit + ? Center( + child: CircularProgressIndicator( + color: Colors.black, + ), + ) + : DatasBox( + datas: datas!, + deviceBlockSize: _deviceBlockSize, + ) + : ConnectionErrorBox(); + }, + ), ), ), );