|
|
@ -23,6 +23,13 @@ class _ZxingWriterWidgetState extends State<ZxingWriterWidget> |
|
|
|
with TickerProviderStateMixin { |
|
|
|
with TickerProviderStateMixin { |
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); |
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); |
|
|
|
final TextEditingController _textController = TextEditingController(); |
|
|
|
final TextEditingController _textController = TextEditingController(); |
|
|
|
|
|
|
|
final TextEditingController _widthController = |
|
|
|
|
|
|
|
TextEditingController(text: "300"); |
|
|
|
|
|
|
|
final TextEditingController _heightController = |
|
|
|
|
|
|
|
TextEditingController(text: "300"); |
|
|
|
|
|
|
|
final TextEditingController _marginController = |
|
|
|
|
|
|
|
TextEditingController(text: "10"); |
|
|
|
|
|
|
|
final TextEditingController _eccController = TextEditingController(text: "0"); |
|
|
|
|
|
|
|
|
|
|
|
bool isAndroid() => Theme.of(context).platform == TargetPlatform.android; |
|
|
|
bool isAndroid() => Theme.of(context).platform == TargetPlatform.android; |
|
|
|
|
|
|
|
|
|
|
@ -41,6 +48,30 @@ class _ZxingWriterWidgetState extends State<ZxingWriterWidget> |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
|
|
|
|
|
const SizedBox(height: 20), |
|
|
|
|
|
|
|
// Input multiline text |
|
|
|
|
|
|
|
TextFormField( |
|
|
|
|
|
|
|
controller: _textController, |
|
|
|
|
|
|
|
keyboardType: TextInputType.multiline, |
|
|
|
|
|
|
|
maxLines: null, |
|
|
|
|
|
|
|
maxLength: _maxTextLength, |
|
|
|
|
|
|
|
onChanged: (value) { |
|
|
|
|
|
|
|
setState(() {}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
decoration: InputDecoration( |
|
|
|
|
|
|
|
border: const OutlineInputBorder(), |
|
|
|
|
|
|
|
filled: true, |
|
|
|
|
|
|
|
labelText: 'Enter barcode text here', |
|
|
|
|
|
|
|
counterText: |
|
|
|
|
|
|
|
'${_textController.value.text.length} / $_maxTextLength', |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
validator: (value) { |
|
|
|
|
|
|
|
if (value?.isEmpty == true) { |
|
|
|
|
|
|
|
return 'Please enter some text'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
const SizedBox(height: 20), |
|
|
|
const SizedBox(height: 20), |
|
|
|
// Format DropDown button |
|
|
|
// Format DropDown button |
|
|
|
DropdownButtonFormField<int>( |
|
|
|
DropdownButtonFormField<int>( |
|
|
@ -58,41 +89,111 @@ class _ZxingWriterWidgetState extends State<ZxingWriterWidget> |
|
|
|
}, |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
const SizedBox(height: 20), |
|
|
|
const SizedBox(height: 20), |
|
|
|
// Input multiline text |
|
|
|
Row( |
|
|
|
TextFormField( |
|
|
|
children: [ |
|
|
|
controller: _textController, |
|
|
|
Flexible( |
|
|
|
keyboardType: TextInputType.multiline, |
|
|
|
child: TextFormField( |
|
|
|
maxLines: null, |
|
|
|
controller: _widthController, |
|
|
|
maxLength: _maxTextLength, |
|
|
|
keyboardType: TextInputType.number, |
|
|
|
onChanged: (value) { |
|
|
|
decoration: const InputDecoration( |
|
|
|
setState(() {}); |
|
|
|
labelText: 'Width', |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
validator: (value) { |
|
|
|
|
|
|
|
final width = int.tryParse(value ?? ''); |
|
|
|
|
|
|
|
if (width == null) { |
|
|
|
|
|
|
|
return 'Invalid number'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
}, |
|
|
|
}, |
|
|
|
decoration: InputDecoration( |
|
|
|
|
|
|
|
border: const OutlineInputBorder(), |
|
|
|
|
|
|
|
filled: true, |
|
|
|
|
|
|
|
hintText: 'Enter text to create a barcode', |
|
|
|
|
|
|
|
counterText: |
|
|
|
|
|
|
|
'${_textController.value.text.length} / $_maxTextLength', |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
const SizedBox(width: 8), |
|
|
|
|
|
|
|
Flexible( |
|
|
|
|
|
|
|
child: TextFormField( |
|
|
|
|
|
|
|
controller: _heightController, |
|
|
|
|
|
|
|
keyboardType: TextInputType.number, |
|
|
|
|
|
|
|
decoration: const InputDecoration( |
|
|
|
|
|
|
|
labelText: 'Height', |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
validator: (value) { |
|
|
|
|
|
|
|
final width = int.tryParse(value ?? ''); |
|
|
|
|
|
|
|
if (width == null) { |
|
|
|
|
|
|
|
return 'Invalid number'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
const SizedBox(height: 20), |
|
|
|
|
|
|
|
Row( |
|
|
|
|
|
|
|
children: [ |
|
|
|
|
|
|
|
Flexible( |
|
|
|
|
|
|
|
child: TextFormField( |
|
|
|
|
|
|
|
controller: _marginController, |
|
|
|
|
|
|
|
keyboardType: TextInputType.number, |
|
|
|
|
|
|
|
decoration: const InputDecoration( |
|
|
|
|
|
|
|
labelText: 'Margin', |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
validator: (value) { |
|
|
|
|
|
|
|
final width = int.tryParse(value ?? ''); |
|
|
|
|
|
|
|
if (width == null) { |
|
|
|
|
|
|
|
return 'Invalid number'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
const SizedBox(width: 8), |
|
|
|
|
|
|
|
Flexible( |
|
|
|
|
|
|
|
child: TextFormField( |
|
|
|
|
|
|
|
controller: _eccController, |
|
|
|
|
|
|
|
keyboardType: TextInputType.number, |
|
|
|
|
|
|
|
decoration: const InputDecoration( |
|
|
|
|
|
|
|
labelText: 'ECC Level', |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
validator: (value) { |
|
|
|
|
|
|
|
final width = int.tryParse(value ?? ''); |
|
|
|
|
|
|
|
if (width == null) { |
|
|
|
|
|
|
|
return 'Invalid number'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
const SizedBox(height: 20), |
|
|
|
// Write button |
|
|
|
// Write button |
|
|
|
ElevatedButton( |
|
|
|
ElevatedButton( |
|
|
|
onPressed: () { |
|
|
|
onPressed: createBarcode, |
|
|
|
|
|
|
|
child: const Text('Create'), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
const SizedBox(height: 20), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void createBarcode() { |
|
|
|
if (_formKey.currentState?.validate() ?? false) { |
|
|
|
if (_formKey.currentState?.validate() ?? false) { |
|
|
|
_formKey.currentState?.save(); |
|
|
|
_formKey.currentState?.save(); |
|
|
|
FocusScope.of(context).unfocus(); |
|
|
|
FocusScope.of(context).unfocus(); |
|
|
|
final text = _textController.value.text; |
|
|
|
final text = _textController.value.text; |
|
|
|
const width = 300; |
|
|
|
final width = int.parse(_widthController.value.text); |
|
|
|
const height = 300; |
|
|
|
final height = int.parse(_heightController.value.text); |
|
|
|
|
|
|
|
final margin = int.parse(_marginController.value.text); |
|
|
|
|
|
|
|
final ecc = int.parse(_eccController.value.text); |
|
|
|
var result = FlutterZxing.encodeBarcode( |
|
|
|
var result = FlutterZxing.encodeBarcode( |
|
|
|
text, width, height, _codeFormat, 5, 0); |
|
|
|
text, width, height, _codeFormat, margin, ecc); |
|
|
|
String? error; |
|
|
|
String? error; |
|
|
|
if (result.isValidBool) { |
|
|
|
if (result.isValidBool) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
final img = |
|
|
|
final img = imglib.Image.fromBytes(width, height, result.bytes); |
|
|
|
imglib.Image.fromBytes(width, height, result.bytes); |
|
|
|
final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img)); |
|
|
|
final encodedBytes = |
|
|
|
|
|
|
|
Uint8List.fromList(imglib.encodeJpg(img)); |
|
|
|
|
|
|
|
widget.onSuccess?.call(result, encodedBytes); |
|
|
|
widget.onSuccess?.call(result, encodedBytes); |
|
|
|
} on Exception catch (e) { |
|
|
|
} on Exception catch (e) { |
|
|
|
error = e.toString(); |
|
|
|
error = e.toString(); |
|
|
@ -105,14 +206,5 @@ class _ZxingWriterWidgetState extends State<ZxingWriterWidget> |
|
|
|
widget.onError?.call(error); |
|
|
|
widget.onError?.call(error); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
child: const Text('Create'), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
const SizedBox(height: 20), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|