Set progress & toast for some other events

This commit is contained in:
fhkhd
2024-01-31 22:24:31 +03:30
parent 86feef9a38
commit 725b8dc30b
6 changed files with 526 additions and 358 deletions
+190 -118
View File
@@ -3,6 +3,7 @@ import 'package:cssd/models/item_model.dart';
import 'package:cssd/providers/auth.dart';
import 'package:cssd/providers/items.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
@@ -51,7 +52,9 @@ class ItemItemBox extends StatelessWidget {
// width: 3 * _deviceBlockSize,
// ),
// Spacer(),
SizedBox(width: 4,),
SizedBox(
width: 4,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
@@ -219,126 +222,193 @@ class ItemItemBox extends StatelessWidget {
SizedBox(
width: 5.0,
),
userData['roles']?.contains('User') ?? false
(userData['roles']?.contains('User') ?? false)
? Container()
: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
InkWell(
customBorder: CircleBorder(),
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
'Are you Reject this item?'
: item?.status == "suspended"
? Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
InkWell(
customBorder: CircleBorder(),
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
'Are you Reject this item?'),
actions: <Widget>[
Consumer<ItemProvider>(
builder: (context,
itemProvider, _) {
return itemProvider
.isloadingButton
? CircularProgressIndicator(
color: Colors.black,
)
: TextButton(
onPressed:
() async {
itemProvider
.setLoadingButton();
await Provider.of<
ItemProvider>(
context,
listen:
false)
.changeStatus(
item!.id,
"rejected")
.then(
(value) {
if (value) {
print(
'true');
}
Navigator.of(
context)
.pop();
Navigator.of(
context)
.popAndPushNamed(
Routes
.itemResultScreen);
Fluttertoast
.showToast(
msg:
"Item is rejected.",
toastLength:
Toast
.LENGTH_SHORT,
gravity:
ToastGravity
.BOTTOM,
);
itemProvider
.resetLoadingButton();
},
);
},
child: Text('Yes'),
);
},
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('No'),
),
],
);
},
);
},
child: Container(
padding: EdgeInsets.all(7),
width: 8 * _deviceBlockSize,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: kPink),
child: Icon(
Icons.close,
size: 4 * _deviceBlockSize,
color: Colors.white,
),
),
),
actions: <Widget>[
TextButton(
onPressed: () {
Provider.of<ItemProvider>(context,
listen: false)
.changeStatus(item!.id, "rejected")
.then(
(value) {
if (value) {
print('true');
}
Navigator.of(context).pop();
// Navigator.of(context)
// .popAndPushNamed(Routes
// .itemResultScreen);
},
);
},
child: Text('Yes'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('No'),
),
],
);
},
);
},
child: Container(
padding: EdgeInsets.all(7),
width: 8 * _deviceBlockSize,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: kPink
),
child: Icon(
Icons.close ,
size: 4 * _deviceBlockSize,
color: Colors.white,
),
),
),
SizedBox(
width: 5,
),
InkWell(
customBorder: CircleBorder(),
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
'Are you Confirm this item?',
SizedBox(
width: 5,
),
actions: <Widget>[
TextButton(
onPressed: () {
Provider.of<ItemProvider>(context,
listen: false)
.changeStatus(item!.id, "approved")
.then(
(value) {
if (value) {
print('true');
}
Navigator.of(context).pop();
// Navigator.of(context)
// .popAndPushNamed(Routes
// .itemResultScreen);
},
);
},
child: Text('Yes'),
InkWell(
customBorder: CircleBorder(),
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
'Are you Confirm this item?',
),
actions: <Widget>[
Consumer<ItemProvider>(builder:
(context, itemProvider, _) {
return itemProvider
.isloadingButton
? CircularProgressIndicator(
color: Colors.black,
)
: TextButton(
onPressed: () async {
itemProvider
.setLoadingButton();
await Provider.of<
ItemProvider>(
context,
listen:
false)
.changeStatus(
item!.id,
"approved")
.then(
(value) {
if (value) {
print('true');
}
Navigator.of(
context)
.pop();
Navigator.of(
context)
.popAndPushNamed(
Routes
.itemResultScreen);
Fluttertoast
.showToast(
msg:
"Item is Confirmed.",
toastLength: Toast
.LENGTH_SHORT,
gravity:
ToastGravity
.BOTTOM,
);
itemProvider
.resetLoadingButton();
},
);
},
child: Text('Yes'),
);
}),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('No'),
),
],
);
},
);
},
child: Container(
padding: EdgeInsets.all(7),
width: 8 * _deviceBlockSize,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: kBlue,
),
child: Icon(
Icons.check,
size: 4 * _deviceBlockSize,
color: Colors.white,
),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('No'),
),
],
);
},
);
},
child: Container(
padding: EdgeInsets.all(7),
width: 8 * _deviceBlockSize,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: kBlue,
),
child: Icon(
Icons.check,
size: 4 * _deviceBlockSize,
color: Colors.white,
),
),
),
],
),
),
],
)
: Container(),
SizedBox(
width: 5.0,
),
@@ -368,7 +438,9 @@ class ItemItemBox extends StatelessWidget {
),
],
),
SizedBox(width: 4,)
SizedBox(
width: 4,
)
],
),
),