mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 19:58:56 +03:30
370 lines
15 KiB
Dart
Executable File
370 lines
15 KiB
Dart
Executable File
import 'package:cssd/config/colors.dart';
|
|
import 'package:cssd/config/routes.dart';
|
|
import 'package:cssd/models/item_model.dart';
|
|
import 'package:cssd/providers/connectivity.dart';
|
|
import 'package:cssd/providers/my_items.dart';
|
|
import 'package:cssd/providers/users.dart';
|
|
import 'package:cssd/widgets/CycleScreens/Result/banner.dart';
|
|
import 'package:cssd/widgets/CycleScreens/Result/search_box.dart';
|
|
import 'package:cssd/widgets/Global/internet_error.dart';
|
|
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:provider/provider.dart';
|
|
|
|
class ItemsTransferScreen extends StatefulWidget {
|
|
final bool? isAdmin;
|
|
final ItemDetailObject? items;
|
|
const ItemsTransferScreen({
|
|
super.key,
|
|
this.isAdmin,
|
|
this.items,
|
|
});
|
|
|
|
@override
|
|
State<ItemsTransferScreen> createState() => _ItemsTransferScreenState();
|
|
}
|
|
|
|
class _ItemsTransferScreenState extends State<ItemsTransferScreen> {
|
|
bool _isInit = true;
|
|
ScrollController? sc;
|
|
TextEditingController searchCTRL = new TextEditingController();
|
|
ItemDetailObject? itemData;
|
|
|
|
@override
|
|
void initState() {
|
|
sc = new ScrollController();
|
|
print(itemData);
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() async {
|
|
if (_isInit) {
|
|
itemData =
|
|
ModalRoute.of(context)!.settings.arguments as ItemDetailObject?;
|
|
var userResults = Provider.of<UsersProvider>(context);
|
|
userResults.resetSelectedUser();
|
|
userResults.setLoading();
|
|
String medicalCenterId =
|
|
await userResults.getUserMedicalCenter() as String;
|
|
print(medicalCenterId);
|
|
userResults.getUsers(medicalCenterId).then(
|
|
(_) {
|
|
userResults.resetLoading();
|
|
sc!.addListener(
|
|
() {
|
|
if (sc!.position.pixels == sc!.position.maxScrollExtent &&
|
|
searchCTRL.text == '') {
|
|
var userResults = Provider.of<UsersProvider>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
userResults.getUsers(medicalCenterId);
|
|
}
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
_isInit = false;
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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,),),
|
|
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,
|
|
),
|
|
)
|
|
: 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,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
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: 300,
|
|
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,
|
|
),
|
|
TransferDestroyButton(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
firstColor: kDarkBlue,
|
|
secondColor: kDarkBlueSub,
|
|
onTap: () {
|
|
Provider.of<MyItemProvider>(
|
|
context,
|
|
listen: false,
|
|
).transferItems(
|
|
itemData!.id,
|
|
Provider.of<UsersProvider>(
|
|
context,
|
|
listen: false)
|
|
.saveUserId!,
|
|
);
|
|
Navigator.of(context).pop();
|
|
Navigator.of(context)
|
|
.popAndPushNamed(Routes
|
|
.myItemsResultScreen);
|
|
},
|
|
text: 'Transfer',
|
|
),
|
|
SizedBox(
|
|
height: 5.0,
|
|
),
|
|
CancelTransferButton(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
color: kPink,
|
|
onTap: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
text: 'Transfer',
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: ConnectionErrorBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Container ItemCard(double _deviceBlockSize, ItemDetailObject item) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.grey),
|
|
borderRadius: BorderRadius.circular(5),
|
|
),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: <Widget>[
|
|
Container(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: Text(
|
|
item.id,
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 3 * _deviceBlockSize,
|
|
),
|
|
// Spacer(),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Container(
|
|
width: 40 * _deviceBlockSize,
|
|
child: Text(
|
|
item.name,
|
|
style: TextStyle(
|
|
fontSize: 3 * _deviceBlockSize,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
width: 30 * _deviceBlockSize,
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'Size: ',
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 3 * _deviceBlockSize,
|
|
color: Colors.grey,
|
|
),
|
|
),
|
|
Text(
|
|
item.size,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 3 * _deviceBlockSize,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
width: 30 * _deviceBlockSize,
|
|
child: Row(
|
|
children: <Widget>[
|
|
Text(
|
|
'User: ',
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontSize: 3 * _deviceBlockSize,
|
|
),
|
|
),
|
|
Text(
|
|
item.userName,
|
|
style: TextStyle(
|
|
fontSize: 3 * _deviceBlockSize,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|