From 0a9b75a6c243fab6ef58452837cd1ce646b1e650 Mon Sep 17 00:00:00 2001 From: fhkhd Date: Tue, 23 Jan 2024 14:29:56 +0330 Subject: [PATCH] Fix lable and subForms in test forms --- .../TestResultScreens/Add/form_creator.dart | 161 +++++++++++++++--- 1 file changed, 142 insertions(+), 19 deletions(-) diff --git a/lib/widgets/TestResultScreens/Add/form_creator.dart b/lib/widgets/TestResultScreens/Add/form_creator.dart index 64210eb..dbf12eb 100755 --- a/lib/widgets/TestResultScreens/Add/form_creator.dart +++ b/lib/widgets/TestResultScreens/Add/form_creator.dart @@ -55,7 +55,7 @@ class _FormCreatorState extends State { var items = Provider.of(context).inputItems; List listWidgets = []; formItems = items; - + print("itemmmm : ${formItems[1]}"); for (var count = 0; count < formItems.length; count++) { Map item = formItems[count]; @@ -172,7 +172,7 @@ class _FormCreatorState extends State { ); } - if (item['type'] == "Text") { + if (item['type'] == "Text" && item['name'] != null) { // print(item['require_scanner'].toString()); TextEditingController idCTRL = new TextEditingController(); final _media = MediaQuery.of(context); @@ -261,6 +261,126 @@ class _FormCreatorState extends State { ); } + if (item['type'] == "Form") { + List formWidget = []; + formWidget.add(Text( + item['name'], + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16.0), + )); + var children = item['children'] as List; + for (var index = 0; index < children.length; index++) { + Map child = children[index]; + if (child['type'] == "Time") { + formWidget.add( + Padding( + padding: const EdgeInsets.all(8.0), + child: TextFormField( + inputFormatters: [ + LengthLimitingTextInputFormatter(5), + FilteringTextInputFormatter.digitsOnly, + // BlacklistingTextInputFormatter.singleLineFormatter, + TextInputFormatter.withFunction( + (TextEditingValue oldValue, TextEditingValue newValue) { + final int newTextLength = newValue.text.length; + int selectionIndex = newValue.selection.end; + int usedSubstringIndex = 0; + final StringBuffer newText = StringBuffer(); + if (newTextLength >= 2) { + newText.write( + newValue.text.substring(0, usedSubstringIndex = 2) + + ':'); + if (newValue.selection.end >= 2) selectionIndex++; + } + // Dump the rest. + if (newTextLength >= usedSubstringIndex) + newText + .write(newValue.text.substring(usedSubstringIndex)); + return TextEditingValue( + text: newText.toString(), + selection: + TextSelection.collapsed(offset: selectionIndex), + ); + }) + ], + keyboardType: TextInputType.datetime, + decoration: InputDecoration( + labelText: child['name'] ?? "", + border: UnderlineInputBorder(), + contentPadding: EdgeInsets.all(0), + ), + // initialValue: item['value'] ?? '', + onChanged: (String value) { + children[index]['value'] = value; + _handleChanged(); + }, + ), + ), + ); + } + if (child['type'] == "Range" || + child['type'] == "Temperature" || + child['type'] == "Pressure") { + double startValue, endValue; + if (child['type'] == "Range") { + startValue = double.parse(child['options'][0]['title']); + endValue = double.parse(child['options'][1]['title']); + } else { + startValue = child['type'] == "Temperature" ? 0.0 : -1.0; + endValue = child['type'] == "Temperature" ? 200.0 : 3.0; + } + + children[index]['value'] = children[index]['value'] ?? startValue; + // int divisions = (endValue - startValue).round(); + formWidget.add( + Padding( + padding: EdgeInsets.only(top: 35, left: 10, right: 10), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(child['type']), + Text(children[index]['value'].toString()), + ], + ), + Slider( + min: startValue, + max: endValue, + value: children[index]['value'], + // label: '${formItems[count]['value'].round()}', + // divisions: divisions, + onChanged: (double value) { + setState(() { + children[index]['value'] = + double.parse(value.toStringAsFixed(2)); + }); + // print(formItems[count]['value']); + }, + // semanticFormatterCallback: (double newValue) { + // return '${newValue.round()}'; + // }, + ), + ], + ), + ), + ); + } + } + listWidgets.add(Container( + margin: EdgeInsets.only(top: 10), + decoration: BoxDecoration(border: Border.all(color: Colors.grey)), + child: ListView.builder( + padding: EdgeInsets.all(widget.padding ?? 6.0), + itemCount: formWidget.length, + itemBuilder: (context, index) { + return formWidget[index]; + }, + shrinkWrap: true, + controller: ScrollController(keepScrollOffset: false), + ), + )); + } if (item['type'] == "Range" || item['type'] == "Temperature" || item['type'] == "Pressure") { @@ -558,7 +678,8 @@ class _FormCreatorState extends State { cameraIcon: Icon( Icons.camera_alt, color: Colors.red, - ), //cameraIcon and galleryIcon can change. If no icon provided default icon will be present + ), + //cameraIcon and galleryIcon can change. If no icon provided default icon will be present cameraText: Text( "From Camera", style: TextStyle(color: Colors.red), @@ -571,28 +692,30 @@ class _FormCreatorState extends State { } Future loadAssetsFromFilePicker(BuildContext context) async { - var providerObject = Provider.of(context, listen: false); - List files = providerObject.catchImages; - var image = await ImagePicker.platform.pickImage( - source: ImageSource.gallery, - imageQuality: 25, - ); - if (image != null) { - files.add( - PlatformFile( - path: image.path, - name: "item_image", - bytes: File(image.path).readAsBytesSync(), - size: File(image.path).lengthSync(), - ), - ); + var providerObject = + Provider.of(context, listen: false); + List files = providerObject.catchImages; + var image = await ImagePicker.platform.pickImage( + source: ImageSource.gallery, + imageQuality: 25, + ); + if (image != null) { + files.add( + PlatformFile( + path: image.path, + name: "item_image", + bytes: File(image.path).readAsBytesSync(), + size: File(image.path).lengthSync(), + ), + ); providerObject.setCatchImages(files); providerObject.setImages(); } } Future loadAssetsFromCamera(BuildContext context) async { - var providerObject = Provider.of(context, listen: false); + var providerObject = + Provider.of(context, listen: false); List _catchImages = providerObject.catchImages; var image = await ImagePicker.platform.pickImage( source: ImageSource.camera,