This commit is contained in:
erfan hayat'bakhsh
2020-09-13 11:49:53 +04:30
parent 641c4ac776
commit 20cc775bc1
27 changed files with 395 additions and 88 deletions
@@ -1,10 +1,12 @@
import 'dart:io';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:cssd/config/routes.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image_picker_gallery_camera/image_picker_gallery_camera.dart';
import 'package:meta/meta.dart';
import 'package:multiselect_formfield/multiselect_formfield.dart';
@@ -119,7 +121,8 @@ class _FormCreatorState extends State<FormCreator> {
),
InkWell(
onTap: () async {
await Navigator.of(context).pushNamed(Routes.captureImageScreen);
await Navigator.of(context)
.pushNamed(Routes.captureImageScreen);
// await captureImage(context);
},
child: Container(
@@ -164,21 +167,90 @@ class _FormCreatorState extends State<FormCreator> {
}
if (item['type'] == "Text") {
print(item['name']);
TextEditingController idCTRL = new TextEditingController();
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;
listWidgets.add(
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
decoration: InputDecoration(
labelText: item['name'] ?? "",
border: UnderlineInputBorder(),
contentPadding: EdgeInsets.all(0),
),
initialValue: item['value'] ?? '',
onChanged: (String value) {
formItems[count]['value'] = value;
_handleChanged();
},
),
child: item['name'] != 'Autoclave ID'
? TextFormField(
controller: idCTRL,
decoration: InputDecoration(
labelText: item['name'] ?? "",
border: UnderlineInputBorder(),
contentPadding: EdgeInsets.all(0),
),
initialValue: item['value'] ?? '',
onChanged: (String value) {
formItems[count]['value'] = value;
_handleChanged();
},
)
: Container(
child: Row(
children: [
Flexible(
flex: 8,
child: TextFormField(
controller: idCTRL,
decoration: InputDecoration(
labelText: item['name'] ?? "",
border: UnderlineInputBorder(),
contentPadding: EdgeInsets.all(0),
),
initialValue: item['value'] ?? '',
onChanged: (String value) {
formItems[count]['value'] = value;
_handleChanged();
},
),
),
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);
idCTRL.text = result;
formItems[count]['value'] = result;
_handleChanged();
// Navigator.of(context).pushNamed(
// CycleDetailScreen.route,
// arguments: result,
// );
}
},
);
},
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black,
),
child: Icon(
FontAwesomeIcons.barcode,
size: 5 * _deviceBlockSize,
color: Colors.white,
),
),
),
),
],
),
),
),
);
}
@@ -622,3 +694,27 @@ class ImageBox extends StatelessWidget {
);
}
}
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';
}
try {
var id = barcode.rawContent.contains('www.cssd-doc.com')
? barcode.rawContent.split('/')[5]
: barcode.rawContent;
return id;
} catch (_) {
return 'null';
}
} on PlatformException catch (_) {
return 'access';
} catch (_) {
return 'error';
}
}