Files
cssd/lib/widgets/CycleScreens/Add/add_label_box.dart
T
2021-06-21 14:14:54 +04:30

252 lines
9.9 KiB
Dart

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 '../../../providers/cycles.dart';
class CycleAddLabelBox extends StatelessWidget {
const CycleAddLabelBox({
Key key,
@required double deviceBlockSize,
@required this.labelValues,
@required this.labelVals,
@required this.initialLabelValue,
@required this.index,
}) : _deviceBlockSize = deviceBlockSize,
super(key: key);
final double _deviceBlockSize;
final TextEditingController labelValues;
final List<String> labelVals;
final String initialLabelValue;
final int index;
@override
Widget build(BuildContext context) {
return Container(
// color: Colors.blue,
height: 150,
child: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(
right: 10,
bottom: 30,
left: 10,
top: 10,
),
decoration: BoxDecoration(
border: Border(
left: BorderSide(color: Colors.black, width: 2),
right: BorderSide(color: Colors.grey),
bottom: BorderSide(color: Colors.grey),
top: BorderSide(color: Colors.grey),
),
),
height: 120,
child: Container(
padding: EdgeInsets.symmetric(vertical: 5),
// height: 65,
child: Row(
// width: double.infinity,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(
FontAwesomeIcons.alignLeft,
color: Colors.grey,
size: 7 * _deviceBlockSize,
),
SizedBox(
width: 4 * _deviceBlockSize,
),
Expanded(
// width: MediaQuery.of(context).size.width - 70,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
SizedBox(
width: _deviceBlockSize,
),
Text(
'Select Labels Included',
style: TextStyle(
fontSize: 3.5 * _deviceBlockSize,
color: Colors.grey,
fontWeight: FontWeight.w100,
),
),
],
),
Row(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width -
(40 * _deviceBlockSize),
// height: 30,
child: DropdownButtonFormField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(
left: _deviceBlockSize,
),
border: InputBorder.none,
),
iconSize: 7 * _deviceBlockSize,
icon: Icon(
FontAwesomeIcons.angleDown,
color: Colors.black,
),
isExpanded: true,
hint: Container(
// width: 100,
height: 70,
padding: const EdgeInsets.symmetric(
horizontal: 0),
child: TextFormField(
controller: labelValues,
decoration: InputDecoration(
contentPadding: EdgeInsets.only(
bottom: 12,
),
isDense: true,
),
style: TextStyle(
fontWeight: FontWeight.w700,
color: Colors.black,
fontSize: 5 * _deviceBlockSize,
),
),
),
isDense: true,
items: labelVals.map((val) {
return new DropdownMenuItem<String>(
value: val,
child: Container(
child: Text(
val,
style: TextStyle(
fontSize: 4 * _deviceBlockSize,
),
),
),
);
}).toList(),
onChanged: (val) {
Provider.of<CyclesProvider>(context,
listen: false)
.changeLabelVal(val, index);
// setState(() {
// labelValues[index]
// .text = val;
// });
},
),
),
Spacer(),
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);
Provider.of<CyclesProvider>(context,
listen: false)
.changeLabelVal(result, index);
// 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,
),
),
)
],
),
]),
),
],
),
),
),
Positioned(
bottom: 15,
right: 0,
child: InkWell(
onTap: () {
Provider.of<CyclesProvider>(context).addLabelVal();
// setState(
// () {
// curLabelVal += 1;
// TextEditingController lbl =
// new TextEditingController();
// lbl.text = initialLabelValue;
// labelValues.add(lbl);
// },
// );
},
child: Container(
padding: EdgeInsets.all(3),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.deepOrange,
),
child: Icon(
Icons.add,
color: Colors.white,
),
),
),
),
],
),
);
}
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';
}
}
}