Improve navigation back

This commit is contained in:
fhkhd
2024-03-13 19:20:21 +03:30
parent 3db8ae3cfe
commit 92e02cc84e
10 changed files with 308 additions and 284 deletions
+40 -32
View File
@@ -77,7 +77,12 @@ class _CycleResultScreenState extends State<CycleResultScreen> {
), ),
appBar: AppBar( appBar: AppBar(
titleSpacing: -10, titleSpacing: -10,
title: Text('Home', style: TextStyle(color: Colors.white,),), title: Text(
'Home',
style: TextStyle(
color: Colors.white,
),
),
backgroundColor: Colors.black, backgroundColor: Colors.black,
leading: IconButton( leading: IconButton(
icon: Icon( icon: Icon(
@@ -85,7 +90,7 @@ class _CycleResultScreenState extends State<CycleResultScreen> {
color: Colors.white, color: Colors.white,
size: 35, size: 35,
), ),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pushNamed(Routes.homePage),
), ),
), ),
body: Consumer<ConnectivityProvider>( body: Consumer<ConnectivityProvider>(
@@ -198,37 +203,40 @@ class _CycleResultScreenState extends State<CycleResultScreen> {
color: Colors.black, color: Colors.black,
), ),
) )
: : cycleResults.items?.length != 0
cycleResults.items?.length != 0 ? ? ListView.builder(
ListView.builder( controller: sc,
controller: sc, itemBuilder: (context, index) {
itemBuilder: (context, index) { String labels = '';
String labels = ''; for (var label in cycleResults
for (var label in cycleResults .items![index].label) {
.items![index].label) { labels += label;
labels += label; labels += ' , ';
labels += ' , '; }
} if (labels.length >= 3) {
if (labels.length >= 3) { labels = labels.substring(
labels = labels.substring( 0,
0, labels.length -
labels.length - 3); // remove extra ,
3); // remove extra , }
} return CycleItemBox(
return CycleItemBox( deviceBlockSize:
deviceBlockSize: _deviceBlockSize, _deviceBlockSize,
item: cycleResults.items?[index], item:
labels: labels, cycleResults.items?[index],
labels: labels,
);
},
itemCount:
cycleResults.items?.length,
shrinkWrap: true,
)
: Container(
child: Center(
child: Text(
"There is no item to show."),
),
); );
},
itemCount: cycleResults.items?.length,
shrinkWrap: true,
) :
Container(
child: Center(
child: Text("There is no item to show."),
),
);
}, },
), ),
), ),
+21 -18
View File
@@ -122,7 +122,7 @@ class _ItemResultScreenState extends State<ItemResultScreen> {
color: Colors.white, color: Colors.white,
size: 35, size: 35,
), ),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pushNamed(Routes.homePage),
), ),
), ),
body: Consumer<ConnectivityProvider>( body: Consumer<ConnectivityProvider>(
@@ -251,24 +251,27 @@ class _ItemResultScreenState extends State<ItemResultScreen> {
color: Colors.black, color: Colors.black,
), ),
) )
: itemResults.items?.length != 0 ? : itemResults.items?.length != 0
ListView.builder( ? ListView.builder(
controller: sc, controller: sc,
itemBuilder: (context, index) { itemBuilder: (context, index) {
// remove extra , // remove extra ,
return ItemItemBox( return ItemItemBox(
deviceBlockSize: _deviceBlockSize, deviceBlockSize:
item: itemResults.items?[index], _deviceBlockSize,
item: itemResults.items?[index],
);
},
itemCount:
itemResults.items?.length,
shrinkWrap: true,
)
: Container(
child: Center(
child: Text(
"There is no item to show."),
),
); );
},
itemCount: itemResults.items?.length,
shrinkWrap: true,
) :
Container(
child: Center(
child: Text("There is no item to show."),
),
);
}, },
), ),
), ),
@@ -85,7 +85,7 @@ class _LabelResultScreenState extends State<LabelResultScreen> {
color: Colors.white, color: Colors.white,
size: 35, size: 35,
), ),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pushNamed(Routes.homePage),
), ),
), ),
body: Consumer<ConnectivityProvider>( body: Consumer<ConnectivityProvider>(
@@ -55,7 +55,8 @@ class _MyItemsResultScreenState extends State<MyItemsResultScreen>
color: Colors.white, color: Colors.white,
size: 35, size: 35,
), ),
onPressed: () => Navigator.of(context).pop(), onPressed: () =>
Navigator.of(context).pushNamed(Routes.homePage),
), ),
// bottom: TabBar( // bottom: TabBar(
// controller: _tabController, // controller: _tabController,
@@ -55,7 +55,8 @@ class _MyPackagesResultScreenState extends State<MyPackagesResultScreen>
color: Colors.white, color: Colors.white,
size: 35, size: 35,
), ),
onPressed: () => Navigator.of(context).pop(), onPressed: () =>
Navigator.of(context).pushNamed(Routes.homePage),
), ),
// bottom: TabBar( // bottom: TabBar(
// controller: _tabController, // controller: _tabController,
@@ -117,13 +117,13 @@ class _PackageResultScreenState extends State<PackageResultScreen> {
), ),
backgroundColor: Colors.black, backgroundColor: Colors.black,
leading: IconButton( leading: IconButton(
icon: Icon( icon: Icon(
Icons.keyboard_arrow_left, Icons.keyboard_arrow_left,
color: Colors.white, color: Colors.white,
size: 35, size: 35,
), ),
onPressed: () => Navigator.of(context).pop(), onPressed: () =>
), Navigator.of(context).pushNamed(Routes.homePage)),
), ),
body: Consumer<ConnectivityProvider>(builder: (ct, connection, _) { body: Consumer<ConnectivityProvider>(builder: (ct, connection, _) {
return connection.conStatus != 'offline' return connection.conStatus != 'offline'
+1 -1
View File
@@ -96,7 +96,7 @@ class _TestResultScreenState extends State<TestResultScreen> {
color: Colors.white, color: Colors.white,
size: 35, size: 35,
), ),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pushNamed(Routes.homePage),
), ),
), ),
body: Consumer<ConnectivityProvider>( body: Consumer<ConnectivityProvider>(
+161 -149
View File
@@ -25,6 +25,7 @@ class _TestVerifyScreenState extends State<TestVerifyScreen> {
ScrollController? sc; ScrollController? sc;
bool _isInit = true; bool _isInit = true;
// List<TestResult> _data = []; // List<TestResult> _data = [];
@override @override
@@ -90,7 +91,7 @@ class _TestVerifyScreenState extends State<TestVerifyScreen> {
color: Colors.white, color: Colors.white,
size: 35, size: 35,
), ),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pushNamed(Routes.homePage),
), ),
), ),
body: Padding( body: Padding(
@@ -285,6 +286,7 @@ class TestItemBox extends StatelessWidget {
super(key: key); super(key: key);
final Map<String, dynamic> userData; final Map<String, dynamic> userData;
final double _deviceBlockSize; final double _deviceBlockSize;
// final String _id; // final String _id;
@override @override
@@ -355,161 +357,171 @@ class TestItemBox extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[ children: <Widget>[
item.verified == 'None' ? item.verified == 'None'
Row( ? Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
InkWell( InkWell(
onTap: () { onTap: () {
showDialog( showDialog(
context: context, context: context,
builder: (ctx) => AlertDialog( builder: (ctx) => AlertDialog(
title: Text('Verify'), title: Text('Verify'),
content: Text( content: Text(
'Are you sure for verify this test?'), 'Are you sure for verify this test?'),
actions: <Widget>[ actions: <Widget>[
Consumer<TestResultsProvider>(builder: Consumer<TestResultsProvider>(builder:
(context, testResultsProvider, child) { (context, testResultsProvider,
return testResultsProvider.isloadingButton child) {
? CircularProgressIndicator( return testResultsProvider
color: Colors.black, .isloadingButton
) ? CircularProgressIndicator(
: TextButton( color: Colors.black,
onPressed: () async { )
testResultsProvider : TextButton(
.setLoadingButton(); onPressed: () async {
await Provider.of< testResultsProvider
TestResultsProvider>( .setLoadingButton();
context, await Provider.of<
listen: false) TestResultsProvider>(
.changeVerification( context,
item.id, 'Verified') listen: false)
.then((result) { .changeVerification(
if (result) { item.id,
print('true'); 'Verified')
} .then((result) {
Navigator.of(ctx).pop(); if (result) {
Navigator.of(context) print('true');
.popAndPushNamed(Routes }
.testVerifyScreen); Navigator.of(ctx).pop();
Fluttertoast.showToast( Navigator.of(context)
msg: "Test is verified.", .popAndPushNamed(Routes
toastLength: .testVerifyScreen);
Toast.LENGTH_SHORT, Fluttertoast.showToast(
gravity: msg:
ToastGravity.BOTTOM, "Test is verified.",
toastLength: Toast
.LENGTH_SHORT,
gravity: ToastGravity
.BOTTOM,
);
testResultsProvider
.resetLoadingButton();
});
},
child: Text('Yes'),
); );
testResultsProvider }),
.resetLoadingButton(); TextButton(
}); onPressed: () {
}, Navigator.of(ctx).pop();
child: Text('Yes'), },
); child: Text('No'),
}), ),
TextButton( ],
onPressed: () { ),
Navigator.of(ctx).pop(); );
}, },
child: Text('No'), child: Container(
padding: EdgeInsets.all(7),
width: 10 * _deviceBlockSize,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: kBlue,
), ),
], child: Icon(
Icons.check,
size: 6 * _deviceBlockSize,
color: Colors.white,
),
),
), ),
); SizedBox(
}, width: 3,
child: Container( ),
padding: EdgeInsets.all(7), InkWell(
width: 10 * _deviceBlockSize, onTap: () {
decoration: BoxDecoration( showDialog(
shape: BoxShape.circle, context: context,
color: kBlue, builder: (ctx) => AlertDialog(
), title: Text('Reject'),
child: Icon( content: Text(
Icons.check, 'Are you sure for reject this test?'),
size: 6 * _deviceBlockSize, actions: <Widget>[
color: Colors.white, Consumer<TestResultsProvider>(
), builder: (context,
), testResultsProvider, _) {
), return testResultsProvider
SizedBox( .isloadingButton
width: 3, ? CircularProgressIndicator(
), color: Colors.black,
InkWell( )
onTap: () { : TextButton(
showDialog( onPressed: () async {
context: context, testResultsProvider
builder: (ctx) => AlertDialog( .setLoadingButton();
title: Text('Reject'), await Provider.of<
content: Text( TestResultsProvider>(
'Are you sure for reject this test?'), context,
actions: <Widget>[ listen: false)
Consumer<TestResultsProvider>( .changeVerification(
builder: item.id,
(context, testResultsProvider, _) { 'NotVerified')
return testResultsProvider .then((result) {
.isloadingButton if (result) {
? CircularProgressIndicator( print('true');
color: Colors.black, }
) Navigator.of(ctx)
: TextButton( .pop();
onPressed: () async { Navigator.of(context)
testResultsProvider .popAndPushNamed(
.setLoadingButton(); Routes
await Provider.of< .testVerifyScreen);
TestResultsProvider>( Fluttertoast
context, .showToast(
listen: false) msg:
.changeVerification( "Test is rejected.",
item.id, toastLength: Toast
'NotVerified') .LENGTH_SHORT,
.then((result) { gravity:
if (result) { ToastGravity
print('true'); .BOTTOM,
} );
Navigator.of(ctx).pop(); testResultsProvider
Navigator.of(context) .resetLoadingButton();
.popAndPushNamed(Routes });
.testVerifyScreen); },
Fluttertoast.showToast( child: Text('Yes'),
msg: "Test is rejected.",
toastLength:
Toast.LENGTH_SHORT,
gravity:
ToastGravity.BOTTOM,
); );
testResultsProvider },
.resetLoadingButton(); ),
}); TextButton(
}, onPressed: () {
child: Text('Yes'), Navigator.of(ctx).pop();
); },
}, child: Text('No'),
),
],
),
);
},
child: Container(
padding: EdgeInsets.all(7),
width: 10 * _deviceBlockSize,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: kPink,
), ),
TextButton( child: Icon(
onPressed: () { Icons.close,
Navigator.of(ctx).pop(); size: 6 * _deviceBlockSize,
}, color: Colors.white,
child: Text('No'),
), ),
], ),
), ),
); ],
}, )
child: Container( : Container(),
padding: EdgeInsets.all(7),
width: 10 * _deviceBlockSize,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: kPink,
),
child: Icon(
Icons.close,
size: 6 * _deviceBlockSize,
color: Colors.white,
),
),
),
],
) : Container(),
SizedBox( SizedBox(
width: _deviceBlockSize, width: _deviceBlockSize,
), ),
+5 -4
View File
@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import '../config/routes.dart';
import '../providers/auth.dart'; import '../providers/auth.dart';
class MyInfoScreen extends StatefulWidget { class MyInfoScreen extends StatefulWidget {
@@ -63,7 +64,7 @@ class _MyInfoScreenState extends State<MyInfoScreen> {
color: Colors.white, color: Colors.white,
size: 35, size: 35,
), ),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pushNamed(Routes.homePage),
), ),
), ),
body: Consumer<ConnectivityProvider>( body: Consumer<ConnectivityProvider>(
@@ -174,9 +175,9 @@ class _MyInfoScreenState extends State<MyInfoScreen> {
Navigator.of(context).pop(); Navigator.of(context).pop();
auth.resetLoading(); auth.resetLoading();
Fluttertoast.showToast( Fluttertoast.showToast(
msg: "Info changed successfully.", msg: "Info changed successfully.",
toastLength: Toast.LENGTH_SHORT, toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM, gravity: ToastGravity.BOTTOM,
); );
}, },
); );
@@ -337,80 +337,78 @@ class MyPackageDetailsDataBox extends StatelessWidget {
SizedBox( SizedBox(
height: 10.0, height: 10.0,
), ),
userData['roles']?.contains('User') ?? false TransferDestroyButton(
? Container() deviceBlockSize: _deviceBlockSize,
: TransferDestroyButton( firstColor: kPink,
deviceBlockSize: _deviceBlockSize, secondColor: kPinkSub,
firstColor: kPink, text: 'Back Items to Item List',
secondColor: kPinkSub, onTap: () {
text: 'Back Items to Item List', showDialog(
onTap: () { context: context,
showDialog( builder: (context) {
context: context, return AlertDialog(
builder: (context) { title: Text(
return AlertDialog( 'Are you sure to destroy this Package?',
title: Text( style: TextStyle(
'Are you sure to destroy this Package?', fontSize: 4 * _deviceBlockSize,
),
),
content: SizedBox(
width: _deviceBlockSize,
height: 220,
child: Column(
children: [
Text(
'By approving, your package will be removed and it can not be used any more.',
style: TextStyle( style: TextStyle(
fontSize: 4 * _deviceBlockSize, fontSize: 3 * _deviceBlockSize,
), ),
), ),
content: SizedBox( SizedBox(
width: _deviceBlockSize, height: 10.0,
height: 220,
child: Column(
children: [
Text(
'By approving, your package will be removed and it can not be used any more.',
style: TextStyle(
fontSize: 3 * _deviceBlockSize,
),
),
SizedBox(
height: 10.0,
),
PackageCard(_deviceBlockSize),
SizedBox(
height: 20.0,
),
TransferDestroyButton(
deviceBlockSize: _deviceBlockSize,
firstColor: kPink,
secondColor: kPinkSub,
onTap: () {
Provider.of<PackageProvider>(context,
listen: false)
.removePackages(datas.id)
.then(
(value) {
Navigator.of(context).pop();
Navigator.pushReplacementNamed(
context,
Routes.myPackagesResultScreen,
);
},
);
},
text: 'Destroy',
),
SizedBox(
height: 5.0,
),
CancelTransferButton(
deviceBlockSize: _deviceBlockSize,
color: kDarkPurple,
onTap: () {
Navigator.pop(context);
},
),
],
),
), ),
); PackageCard(_deviceBlockSize),
}, SizedBox(
); height: 20.0,
}, ),
), TransferDestroyButton(
deviceBlockSize: _deviceBlockSize,
firstColor: kPink,
secondColor: kPinkSub,
onTap: () {
Provider.of<PackageProvider>(context,
listen: false)
.removePackages(datas.id)
.then(
(value) {
Navigator.of(context).pop();
Navigator.pushReplacementNamed(
context,
Routes.myPackagesResultScreen,
);
},
);
},
text: 'Destroy',
),
SizedBox(
height: 5.0,
),
CancelTransferButton(
deviceBlockSize: _deviceBlockSize,
color: kDarkPurple,
onTap: () {
Navigator.pop(context);
},
),
],
),
),
);
},
);
},
),
SizedBox( SizedBox(
height: 20, height: 20,
), ),