mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-13 12:58:56 +03:30
128 lines
3.6 KiB
Dart
Executable File
128 lines
3.6 KiB
Dart
Executable File
// ignore_for_file: must_be_immutable
|
|
|
|
import 'package:cssd/config/colors.dart';
|
|
import 'package:cssd/providers/items.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../../config/routes.dart';
|
|
|
|
class ItemAddSaveButton extends StatefulWidget {
|
|
ItemAddSaveButton({
|
|
Key? key,
|
|
required GlobalKey<FormState> form,
|
|
this.batchId,
|
|
required this.nameCTRL,
|
|
required this.descriptionCTRL,
|
|
required this.udiCTRL,
|
|
required double deviceBlockSize,
|
|
required this.sizeCTRL,
|
|
required this.specificCTRL,
|
|
required this.dateValue,
|
|
required this.isLoading,
|
|
}) : _form = form,
|
|
_deviceBlockSize = deviceBlockSize,
|
|
super(key: key);
|
|
|
|
final GlobalKey<FormState> _form;
|
|
final TextEditingController nameCTRL;
|
|
final TextEditingController descriptionCTRL;
|
|
final TextEditingController udiCTRL;
|
|
final TextEditingController sizeCTRL;
|
|
final TextEditingController specificCTRL;
|
|
final String dateValue;
|
|
final String? batchId;
|
|
final double _deviceBlockSize;
|
|
bool isLoading;
|
|
|
|
@override
|
|
State<ItemAddSaveButton> createState() => _ItemAddSaveButtonState();
|
|
}
|
|
|
|
class _ItemAddSaveButtonState extends State<ItemAddSaveButton> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return InkWell(
|
|
onTap: () {
|
|
if (!widget._form.currentState!.validate()) {
|
|
return;
|
|
}
|
|
setState(() {
|
|
widget.isLoading = true;
|
|
});
|
|
Provider.of<ItemProvider>(context, listen: false)
|
|
.createItemResult(
|
|
widget.nameCTRL.text,
|
|
widget.sizeCTRL.text,
|
|
widget.specificCTRL.text,
|
|
widget.udiCTRL.text,
|
|
widget.descriptionCTRL.text,
|
|
widget.batchId,
|
|
)
|
|
.then(
|
|
(result) {
|
|
setState(() {
|
|
widget.isLoading = false;
|
|
});
|
|
if (result == 'done') {
|
|
showDialog(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
content: Text('Item added.'),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(ctx).pop();
|
|
},
|
|
child: Text('Ok'),
|
|
)
|
|
],
|
|
),
|
|
).then((value) => Navigator.of(context)
|
|
.popAndPushNamed(Routes.testResultScreen));
|
|
}
|
|
},
|
|
);
|
|
showDialog(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
content: Text('Item added.'),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(ctx).pop();
|
|
},
|
|
child: Text('Ok'),
|
|
)
|
|
],
|
|
),
|
|
).then((_) {
|
|
Navigator.of(context).pushReplacementNamed(Routes.itemResultScreen);
|
|
});
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 5 * widget._deviceBlockSize,
|
|
vertical: 10,
|
|
),
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: [kBlue, kBlueSub],
|
|
),
|
|
borderRadius: BorderRadius.circular(7),
|
|
),
|
|
child: Align(
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
'Save',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 5 * widget._deviceBlockSize,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|