mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 20:18:54 +03:30
379 lines
19 KiB
Dart
Executable File
379 lines
19 KiB
Dart
Executable File
import 'package:cssd/config/colors.dart';
|
|
import 'package:cssd/utils/scan.dart';
|
|
import 'package:cssd/widgets/LabelScreens/Add/add_package_box.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
import 'package:intl/intl.dart' as DateEditor;
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../config/routes.dart';
|
|
import '../../providers/connectivity.dart';
|
|
import '../../providers/labels.dart';
|
|
import '../../widgets/Global/internet_error.dart';
|
|
import '../../widgets/LabelScreens/Add/date_picker.dart';
|
|
import '../../widgets/LabelScreens/Add/save_button.dart';
|
|
|
|
class LabelAddScreen extends StatefulWidget {
|
|
@override
|
|
_LabelAddScreenState createState() => _LabelAddScreenState();
|
|
}
|
|
|
|
class _LabelAddScreenState extends State<LabelAddScreen> {
|
|
final _cycleNumberFocusNode = FocusNode();
|
|
TextEditingController lotNumberCTRL = new TextEditingController();
|
|
TextEditingController cycleNumberCTRL = new TextEditingController();
|
|
TextEditingController striizerIdCTRL = new TextEditingController();
|
|
TextEditingController sDateCTRL = new TextEditingController();
|
|
TextEditingController eDateCTRL = new TextEditingController();
|
|
TextEditingController packageCTRL = new TextEditingController();
|
|
|
|
DateTime? dateTimeS;
|
|
|
|
final _form = GlobalKey<FormState>();
|
|
bool isInit = true;
|
|
|
|
// String? packageId;
|
|
// String? previousRoute;
|
|
|
|
List<TextEditingController> labelsCTRL = [TextEditingController()];
|
|
int curLabelVal = 1;
|
|
|
|
@override
|
|
void initState() {
|
|
sDateCTRL.text = DateEditor.DateFormat('y-M-d').format(DateTime.now());
|
|
eDateCTRL.text = DateEditor.DateFormat('y-M-d').format(DateTime.now());
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() async {
|
|
if (isInit) {
|
|
var labelProviderObject = Provider.of<LabelsProvider>(context);
|
|
labelProviderObject.resetPackageVals();
|
|
labelProviderObject.getPackageFilters().then(
|
|
(result) {
|
|
setState(
|
|
() {
|
|
isInit = false;
|
|
},
|
|
);
|
|
},
|
|
);
|
|
var arguments = ModalRoute.of(context)!.settings.arguments;
|
|
if (arguments != null && arguments is Map<dynamic, dynamic>) {
|
|
labelProviderObject.packageId =
|
|
"${arguments['id']} - ${arguments['name']}";
|
|
}
|
|
}
|
|
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final _media = MediaQuery.of(context);
|
|
final double _devicewidth = _media.size.width;
|
|
final double _deviceBlockSize = _devicewidth / 100;
|
|
// String initialLabelValue;
|
|
return Consumer<LabelsProvider>(
|
|
builder: (context, labelsProvider, _) {
|
|
return SafeArea(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
},
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
titleSpacing: -10,
|
|
title: Text(
|
|
'Labels',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
backgroundColor: Colors.black,
|
|
leading: IconButton(
|
|
icon: Icon(
|
|
Icons.keyboard_arrow_left,
|
|
color: Colors.white,
|
|
size: 35,
|
|
),
|
|
onPressed: () {
|
|
labelsProvider.resetLoadingButton();
|
|
Navigator.of(context)
|
|
.pushReplacementNamed(Routes.labelResultScreen);
|
|
},
|
|
),
|
|
),
|
|
body: Consumer<ConnectivityProvider>(
|
|
builder: (ct, connection, _) {
|
|
return connection.conStatus != 'offline'
|
|
? isInit
|
|
? Center(
|
|
child: CircularProgressIndicator(
|
|
color: Colors.black,
|
|
),
|
|
)
|
|
: Form(
|
|
key: _form,
|
|
child: Padding(
|
|
padding: EdgeInsets.all(20),
|
|
child: ListView(
|
|
children: <Widget>[
|
|
Text(
|
|
'Add a Label',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 6 * _deviceBlockSize,
|
|
letterSpacing: 3,
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
Row(
|
|
children: [
|
|
Flexible(
|
|
flex: 8,
|
|
child: TextFormField(
|
|
onChanged: (val) {
|
|
setState(() {
|
|
lotNumberCTRL.text = val +
|
|
' - ' +
|
|
cycleNumberCTRL.text;
|
|
});
|
|
},
|
|
validator: (val) {
|
|
if (val!.isEmpty) {
|
|
return 'Strilizer ID required!';
|
|
}
|
|
return null;
|
|
},
|
|
controller: striizerIdCTRL,
|
|
decoration: InputDecoration(
|
|
icon: Icon(
|
|
FontAwesomeIcons
|
|
.sortNumericDown,
|
|
size: 7 * _deviceBlockSize),
|
|
isDense: true,
|
|
labelText: 'Strilizer ID',
|
|
contentPadding:
|
|
EdgeInsets.symmetric(
|
|
vertical: 2,
|
|
horizontal: 3),
|
|
labelStyle: TextStyle(
|
|
fontWeight: FontWeight.w100,
|
|
fontSize: 4 * _deviceBlockSize,
|
|
),
|
|
),
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
),
|
|
keyboardType:
|
|
TextInputType.visiblePassword,
|
|
textInputAction:
|
|
TextInputAction.next,
|
|
onFieldSubmitted: (_) {
|
|
FocusScope.of(context)
|
|
.requestFocus(
|
|
_cycleNumberFocusNode);
|
|
},
|
|
),
|
|
),
|
|
Flexible(
|
|
flex: 1,
|
|
child: InkWell(
|
|
onTap: () {
|
|
scan().then(
|
|
(String result) {
|
|
if (result == 'cancel') {
|
|
print('cancel');
|
|
} else if (result ==
|
|
'error') {
|
|
print('error');
|
|
} else if (result ==
|
|
'access') {
|
|
print('access');
|
|
} else {
|
|
print(result);
|
|
striizerIdCTRL.text =
|
|
result;
|
|
}
|
|
},
|
|
);
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Colors.black,
|
|
),
|
|
child: Icon(
|
|
Icons.qr_code_scanner,
|
|
size: 5 * _deviceBlockSize,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
TextFormField(
|
|
onChanged: (val) {
|
|
setState(
|
|
() {
|
|
lotNumberCTRL.text =
|
|
striizerIdCTRL.text +
|
|
' - ' +
|
|
val;
|
|
},
|
|
);
|
|
},
|
|
validator: (val) {
|
|
if (val!.isEmpty) {
|
|
return 'Cycle number required!';
|
|
}
|
|
return null;
|
|
},
|
|
controller: cycleNumberCTRL,
|
|
decoration: InputDecoration(
|
|
icon: Icon(
|
|
FontAwesomeIcons.sortNumericDown,
|
|
size: 7 * _deviceBlockSize,
|
|
),
|
|
labelStyle: TextStyle(
|
|
fontWeight: FontWeight.w100,
|
|
fontSize: 4 * _deviceBlockSize,
|
|
),
|
|
isDense: true,
|
|
labelText: 'Cycle Number',
|
|
contentPadding: EdgeInsets.symmetric(
|
|
vertical: 2, horizontal: 3),
|
|
),
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
),
|
|
focusNode: _cycleNumberFocusNode,
|
|
keyboardType: TextInputType.number,
|
|
textInputAction: TextInputAction.done,
|
|
),
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
TextFormField(
|
|
readOnly: true,
|
|
controller: lotNumberCTRL,
|
|
decoration: InputDecoration(
|
|
icon: Icon(
|
|
FontAwesomeIcons.sortNumericDown,
|
|
size: 7 * _deviceBlockSize,
|
|
),
|
|
labelStyle: TextStyle(
|
|
fontWeight: FontWeight.w100,
|
|
fontSize: 4 * _deviceBlockSize,
|
|
),
|
|
isDense: true,
|
|
labelText: 'Lot Number',
|
|
contentPadding: EdgeInsets.symmetric(
|
|
vertical: 2,
|
|
horizontal: 3,
|
|
),
|
|
),
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
),
|
|
keyboardType:
|
|
TextInputType.visiblePassword,
|
|
),
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
Container(
|
|
margin:
|
|
EdgeInsets.symmetric(vertical: 10),
|
|
child: Text(
|
|
'Packages included',
|
|
style: TextStyle(
|
|
color: kLightBlue,
|
|
letterSpacing: 2,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
),
|
|
),
|
|
),
|
|
Consumer<LabelsProvider>(
|
|
builder: (ctx, labelProvider, _) {
|
|
return ListView.builder(
|
|
physics: NeverScrollableScrollPhysics(),
|
|
shrinkWrap: true,
|
|
itemBuilder: (ctx, index) =>
|
|
AddPackageBox(
|
|
text: 'Package ID',
|
|
iconColor: kLightBlueSub,
|
|
deviceBlockSize: _deviceBlockSize,
|
|
values: labelProvider
|
|
.packageValues[index],
|
|
vals: labelProvider.packageVals,
|
|
initialLabelValue:
|
|
labelProvider.initialPackageValue,
|
|
index: index,
|
|
),
|
|
itemCount:
|
|
labelProvider.packageValues.length,
|
|
);
|
|
}),
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
LabelAddDatePicker(
|
|
dateCTRL: sDateCTRL,
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Sterile Date',
|
|
),
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
LabelAddDatePicker(
|
|
dateCTRL: eDateCTRL,
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Expire Date',
|
|
),
|
|
SizedBox(
|
|
height: 70,
|
|
),
|
|
LabelAddSaveButton(
|
|
form: _form,
|
|
lotNumberCTRL: lotNumberCTRL,
|
|
cycleNumberCTRL: cycleNumberCTRL,
|
|
sDateCTRL: sDateCTRL,
|
|
packageValue: Provider.of<LabelsProvider>(
|
|
context,
|
|
listen: false,
|
|
).packageValues,
|
|
eDateCTRL: eDateCTRL,
|
|
striizerIdCTRL: striizerIdCTRL,
|
|
deviceBlockSize: _deviceBlockSize,
|
|
),
|
|
SizedBox(
|
|
height: 100,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: ConnectionErrorBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|