Back button of pages navigate to home

This commit is contained in:
fhkhd
2024-04-20 18:27:55 +04:30
parent 8ac585f94b
commit 34e3f76845
9 changed files with 770 additions and 654 deletions
@@ -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<ItemsTransferScreen> {
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<ConnectivityProvider>(
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: <Widget>[
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<UsersProvider>(context, listen: false)
.searchUsers(value);
},
),
SizedBox(
height: 20,
),
Expanded(
child: Consumer<UsersProvider>(
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<UsersProvider>(
context,
listen: false,
).selectUser(index);
print(userId);
Provider.of<UsersProvider>(
context,
listen: false)
.saveUserId = userId;
Provider.of<UsersProvider>(
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<ConnectivityProvider>(
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: <Widget>[
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<UsersProvider>(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<UsersProvider>(
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<UsersProvider>(
context,
listen: false,
).selectUser(index);
print(userId);
Provider.of<UsersProvider>(
context)
.selectedUserForItems,
)
],
),
SizedBox(
height: 20.0,
),
Consumer<MyItemProvider>(
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<UsersProvider>(
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<MyItemProvider>(
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();
},
),
),
),
),