mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 19:48:56 +03:30
fix bugs and set progress and toast for my items server events
This commit is contained in:
@@ -11,11 +11,14 @@ import 'package:cssd/widgets/MyItemsScreens/Detail/cancel_transfer_button.dart';
|
||||
import 'package:cssd/widgets/MyItemsScreens/Detail/transfer_data_box.dart';
|
||||
import 'package:cssd/widgets/MyItemsScreens/Detail/transfer_destroy_button.dart';
|
||||
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;
|
||||
|
||||
const ItemsTransferScreen({
|
||||
super.key,
|
||||
this.isAdmin,
|
||||
@@ -85,7 +88,12 @@ class _ItemsTransferScreenState extends State<ItemsTransferScreen> {
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
titleSpacing: -10,
|
||||
title: Text('Item Details', style: TextStyle(color: Colors.white,),),
|
||||
title: Text(
|
||||
'Item Details',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.black,
|
||||
leading: IconButton(
|
||||
icon: Icon(
|
||||
@@ -192,7 +200,7 @@ class _ItemsTransferScreenState extends State<ItemsTransferScreen> {
|
||||
),
|
||||
content: SizedBox(
|
||||
width: _deviceBlockSize,
|
||||
height: 300,
|
||||
height: 320,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
@@ -228,27 +236,45 @@ class _ItemsTransferScreenState extends State<ItemsTransferScreen> {
|
||||
SizedBox(
|
||||
height: 20.0,
|
||||
),
|
||||
TransferDestroyButton(
|
||||
deviceBlockSize: _deviceBlockSize,
|
||||
firstColor: kDarkBlue,
|
||||
secondColor: kDarkBlueSub,
|
||||
onTap: () {
|
||||
Provider.of<MyItemProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
).transferItems(
|
||||
itemData!.id,
|
||||
Provider.of<UsersProvider>(
|
||||
context,
|
||||
listen: false)
|
||||
.saveUserId!,
|
||||
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,
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context)
|
||||
.popAndPushNamed(Routes
|
||||
.myItemsResultScreen);
|
||||
},
|
||||
text: 'Transfer',
|
||||
),
|
||||
SizedBox(
|
||||
height: 5.0,
|
||||
|
||||
@@ -256,6 +256,17 @@ class MyItemProvider extends ChangeNotifier {
|
||||
// }
|
||||
// }
|
||||
|
||||
bool isloadingButton = false;
|
||||
void resetLoadingButton() {
|
||||
isloadingButton = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setLoadingButton() {
|
||||
isloadingButton = true;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> transferItems(String itemId, String userId) async {
|
||||
var response = await http.post(
|
||||
Uri.parse(Url.transferItems(itemId)),
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:cssd/providers/my_items.dart';
|
||||
import 'package:cssd/widgets/MyItemsScreens/Detail/cancel_transfer_button.dart';
|
||||
import 'package:cssd/widgets/MyItemsScreens/Detail/transfer_destroy_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:pinch_zoom/pinch_zoom.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -466,25 +467,39 @@ class MyItemsDetailsDataBox extends StatelessWidget {
|
||||
SizedBox(
|
||||
height: 20.0,
|
||||
),
|
||||
TransferDestroyButton(
|
||||
deviceBlockSize: _deviceBlockSize,
|
||||
firstColor: kPink,
|
||||
secondColor: kPinkSub,
|
||||
onTap: () {
|
||||
Provider.of<ItemProvider>(context,
|
||||
listen: false)
|
||||
.removeItems(datas.id)
|
||||
.then(
|
||||
(value) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.pushReplacementNamed(
|
||||
context,
|
||||
Routes.myItemsResultScreen,
|
||||
Consumer<ItemProvider>(
|
||||
builder: (context, itemProvider, child) {
|
||||
return TransferDestroyButton(
|
||||
deviceBlockSize: _deviceBlockSize,
|
||||
firstColor: kPink,
|
||||
secondColor: kPinkSub,
|
||||
isLoadingButton:
|
||||
itemProvider.isloadingButton,
|
||||
onTap: () async {
|
||||
itemProvider.setLoadingButton();
|
||||
await Provider.of<ItemProvider>(context,
|
||||
listen: false)
|
||||
.removeItems(datas.id)
|
||||
.then(
|
||||
(value) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
Navigator.pushReplacementNamed(
|
||||
context,
|
||||
Routes.myItemsResultScreen,
|
||||
);
|
||||
itemProvider.resetLoadingButton();
|
||||
Fluttertoast.showToast(
|
||||
msg: "The item is destroyed.",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
text: 'Destroy',
|
||||
);
|
||||
},
|
||||
text: 'Destroy',
|
||||
),
|
||||
SizedBox(
|
||||
height: 5.0,
|
||||
@@ -603,7 +618,7 @@ class MyItemsDetailsDataBox extends StatelessWidget {
|
||||
),
|
||||
content: SizedBox(
|
||||
width: _deviceBlockSize,
|
||||
height: 220,
|
||||
height: 240,
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
@@ -619,25 +634,34 @@ class MyItemsDetailsDataBox extends StatelessWidget {
|
||||
SizedBox(
|
||||
height: 20.0,
|
||||
),
|
||||
TransferDestroyButton(
|
||||
deviceBlockSize: _deviceBlockSize,
|
||||
firstColor: Colors.black,
|
||||
secondColor: Colors.black87,
|
||||
onTap: () {
|
||||
Provider.of<MyItemProvider>(context,
|
||||
listen: false)
|
||||
.repairItems(datas.id, 'approved')
|
||||
.then(
|
||||
(value) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.pushReplacementNamed(
|
||||
context,
|
||||
Routes.myItemsResultScreen,
|
||||
Consumer<ItemProvider>(
|
||||
builder: (context, itemProvider, child) {
|
||||
return TransferDestroyButton(
|
||||
deviceBlockSize: _deviceBlockSize,
|
||||
firstColor: Colors.black,
|
||||
secondColor: Colors.black87,
|
||||
isLoadingButton: itemProvider.isloadingButton,
|
||||
onTap: () async {
|
||||
itemProvider.setLoadingButton();
|
||||
await Provider.of<MyItemProvider>(context,
|
||||
listen: false)
|
||||
.repairItems(datas.id, 'approved')
|
||||
.then(
|
||||
(value) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
itemProvider.resetLoadingButton();
|
||||
Fluttertoast.showToast(
|
||||
msg: "The item is repaired.",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
text: 'Repair',
|
||||
);
|
||||
},
|
||||
text: 'Repair',
|
||||
),
|
||||
SizedBox(
|
||||
height: 5.0,
|
||||
@@ -824,7 +848,7 @@ class MyItemsDetailsDataBox extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 30 * _deviceBlockSize,
|
||||
width: 40 * _deviceBlockSize,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
|
||||
@@ -9,6 +9,7 @@ class TransferDestroyButton extends StatelessWidget {
|
||||
required this.onTap,
|
||||
required this.text,
|
||||
this.fontSize = 5.0,
|
||||
this.isLoadingButton = false,
|
||||
}) : _deviceBlockSize = deviceBlockSize,
|
||||
super(key: key);
|
||||
final double _deviceBlockSize;
|
||||
@@ -17,6 +18,7 @@ class TransferDestroyButton extends StatelessWidget {
|
||||
final String text;
|
||||
final VoidCallback onTap;
|
||||
final double fontSize;
|
||||
final bool isLoadingButton;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -33,16 +35,22 @@ class TransferDestroyButton extends StatelessWidget {
|
||||
),
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: fontSize * _deviceBlockSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: isLoadingButton
|
||||
? Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: Align(
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: fontSize * _deviceBlockSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user