mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 20:58:54 +03:30
311 lines
14 KiB
Dart
Executable File
311 lines
14 KiB
Dart
Executable File
import 'package:barcode_scan2/barcode_scan2.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../config/routes.dart';
|
|
import '../../providers/connectivity.dart';
|
|
import '../../providers/test_results.dart';
|
|
import '../../widgets/Global/internet_error.dart';
|
|
import '../../widgets/TestResultScreens/Add/selector_box.dart';
|
|
|
|
class TestResultAddScreen extends StatefulWidget {
|
|
@override
|
|
State<StatefulWidget> createState() {
|
|
return _TestResultAddScreenState();
|
|
}
|
|
}
|
|
|
|
class _TestResultAddScreenState extends State<TestResultAddScreen> {
|
|
TextEditingController testTypeCTRL = new TextEditingController();
|
|
final List<String> testTypeVals = [];
|
|
|
|
TextEditingController testCodeCTRL = new TextEditingController();
|
|
bool isInit = true;
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
if (isInit) {
|
|
var testResultProviderObject =
|
|
Provider.of<TestResultsProvider>(context, listen: false);
|
|
testResultProviderObject.resetTests();
|
|
testResultProviderObject.getFilterItems().then((result) {
|
|
for (var testType in result[1].keys) {
|
|
testTypeVals.add(testType);
|
|
}
|
|
testTypeCTRL.text = testTypeVals[0];
|
|
setState(() {
|
|
isInit = false;
|
|
});
|
|
});
|
|
}
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final _media = MediaQuery.of(context);
|
|
// final double _pixelRatio = (_media.size.height / _media.size.width * 7 / 5);
|
|
final double _devicewidth = _media.size.width;
|
|
final double _deviceBlockSize = _devicewidth / 100;
|
|
return PopScope(
|
|
canPop: false,
|
|
onPopInvoked: (didPop) {
|
|
if (didPop) return;
|
|
Navigator.of(context).pushNamed(Routes.homePage);
|
|
// Navigator.pushReplacementNamed(
|
|
// context,
|
|
// Routes.testResultScreen,
|
|
// );
|
|
// return true;
|
|
},
|
|
child: SafeArea(
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
titleSpacing: -10,
|
|
title: Text(
|
|
'Test Results',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
backgroundColor: Colors.black,
|
|
leading: IconButton(
|
|
icon: Icon(
|
|
Icons.keyboard_arrow_left,
|
|
color: Colors.white,
|
|
size: 35,
|
|
),
|
|
// padding: EdgeInsets.all(0),
|
|
onPressed: () => Navigator.of(context)
|
|
.popAndPushNamed(Routes.testResultScreen),
|
|
),
|
|
),
|
|
body: Consumer<ConnectivityProvider>(
|
|
builder: (ct, connection, _) {
|
|
return connection.conStatus != 'offline'
|
|
? isInit
|
|
? Center(
|
|
child: CircularProgressIndicator(
|
|
color: Colors.black,
|
|
),
|
|
)
|
|
: ListView(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 20, vertical: 20),
|
|
children: <Widget>[
|
|
Container(
|
|
padding: EdgeInsets.only(
|
|
top: 10,
|
|
),
|
|
child: Text(
|
|
'Add a Test Result',
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
letterSpacing: 3,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
child: Container(
|
|
margin: EdgeInsets.only(top: 5, bottom: 30),
|
|
padding: EdgeInsets.all(10),
|
|
height: 200,
|
|
decoration: BoxDecoration(border: Border.all()),
|
|
child: Center(
|
|
child: Text(
|
|
'PLease Scan The Test Barcode',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
fontWeight: FontWeight.w100,
|
|
letterSpacing: 3,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
onTap: () {
|
|
scan().then(
|
|
(String result) {
|
|
if (result == 'cancel') {
|
|
print('cancel');
|
|
} else if (result == 'error') {
|
|
print('error');
|
|
} else if (result == 'access') {
|
|
print('access');
|
|
} else {
|
|
Provider.of<TestResultsProvider>(
|
|
context,
|
|
listen: false,
|
|
).testCode = result;
|
|
Navigator.pushNamed(
|
|
context,
|
|
Routes.formTestResultScreen,
|
|
arguments: result,
|
|
);
|
|
}
|
|
},
|
|
);
|
|
},
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.max,
|
|
children: <Widget>[
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: <Widget>[
|
|
Container(
|
|
width: 70 * _deviceBlockSize,
|
|
child: TestResultAddSelectorBox(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
dataCTRL: testTypeCTRL,
|
|
dataVals: testTypeVals,
|
|
label: 'Choose a Test Type',
|
|
),
|
|
),
|
|
Row(
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment.end,
|
|
children: <Widget>[
|
|
Text(
|
|
'OR',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 7 * _deviceBlockSize,
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 8 * _deviceBlockSize,
|
|
),
|
|
Container(
|
|
width: 50 * _deviceBlockSize,
|
|
child: TextFormField(
|
|
onChanged: (val) {
|
|
if (val != '') {
|
|
setState(
|
|
() {
|
|
testTypeCTRL.text = '';
|
|
},
|
|
);
|
|
} else {
|
|
setState(
|
|
() {
|
|
testTypeCTRL.text =
|
|
testTypeVals[0];
|
|
},
|
|
);
|
|
}
|
|
},
|
|
controller: testCodeCTRL,
|
|
decoration: InputDecoration(
|
|
isDense: true,
|
|
icon: Icon(
|
|
FontAwesomeIcons
|
|
.sortNumericDown,
|
|
),
|
|
labelText: 'Enter a Test Code',
|
|
labelStyle: TextStyle(
|
|
fontSize: 3 * _deviceBlockSize,
|
|
),
|
|
contentPadding: EdgeInsets.only(
|
|
bottom: 5,
|
|
top: 5,
|
|
),
|
|
),
|
|
keyboardType:
|
|
TextInputType.visiblePassword,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 40.0,
|
|
),
|
|
Container(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 5 * _deviceBlockSize,
|
|
vertical: 10,
|
|
),
|
|
width: 50 * _deviceBlockSize,
|
|
decoration: BoxDecoration(
|
|
color: Colors.black,
|
|
borderRadius: BorderRadius.circular(7),
|
|
),
|
|
child: Align(
|
|
alignment: Alignment.center,
|
|
child: TextButton(
|
|
child: Text(
|
|
'Select',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
),
|
|
),
|
|
onPressed: () {
|
|
if (testCodeCTRL.text != '') {
|
|
Provider.of<TestResultsProvider>(
|
|
context,
|
|
listen: false,
|
|
).testCode = testCodeCTRL.text;
|
|
Navigator.pushNamed(
|
|
context,
|
|
Routes.formTestResultScreen,
|
|
arguments: testCodeCTRL.text,
|
|
);
|
|
} else if (testTypeCTRL.text !=
|
|
'') {
|
|
Provider.of<TestResultsProvider>(
|
|
context,
|
|
listen: false,
|
|
).testType = testTypeCTRL.text;
|
|
Navigator.pushReplacementNamed(
|
|
context,
|
|
Routes.formTestResultScreen,
|
|
arguments: testTypeCTRL.text,
|
|
);
|
|
}
|
|
// print(testCode);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
width: 5 * _deviceBlockSize,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
)
|
|
: ConnectionErrorBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<String> scan() async {
|
|
try {
|
|
var barcode = await BarcodeScanner.scan();
|
|
if (barcode.type.name == 'Cancelled') {
|
|
return 'cancel';
|
|
} else if (barcode.type.name == 'Failed') {
|
|
return 'error';
|
|
}
|
|
return barcode.rawContent;
|
|
} on PlatformException catch (_) {
|
|
return 'access';
|
|
} catch (_) {
|
|
return 'error';
|
|
}
|
|
}
|
|
}
|