mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 13:33:28 +01:00 
			
		
		
		
	Generated form bugfix (initState not running) - #245
This commit is contained in:
		| @@ -150,6 +150,7 @@ class _GeneratedFormState extends State<GeneratedForm> { | |||||||
|   Map<String, dynamic> values = {}; |   Map<String, dynamic> values = {}; | ||||||
|   late List<List<Widget>> formInputs; |   late List<List<Widget>> formInputs; | ||||||
|   List<List<Widget>> rows = []; |   List<List<Widget>> rows = []; | ||||||
|  |   String? initKey; | ||||||
|  |  | ||||||
|   // If any value changes, call this to update the parent with value and validity |   // If any value changes, call this to update the parent with value and validity | ||||||
|   void someValueChanged({bool isBuilding = false}) { |   void someValueChanged({bool isBuilding = false}) { | ||||||
| @@ -169,13 +170,10 @@ class _GeneratedFormState extends State<GeneratedForm> { | |||||||
|     widget.onValueChanges(returnValues, valid, isBuilding); |     widget.onValueChanges(returnValues, valid, isBuilding); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @override |   initForm() { | ||||||
|   void initState() { |     initKey = widget.key.toString(); | ||||||
|     super.initState(); |  | ||||||
|  |  | ||||||
|     // Initialize form values as all empty |     // Initialize form values as all empty | ||||||
|     values.clear(); |     values.clear(); | ||||||
|     int j = 0; |  | ||||||
|     for (var row in widget.items) { |     for (var row in widget.items) { | ||||||
|       for (var e in row) { |       for (var e in row) { | ||||||
|         values[e.key] = e.defaultValue; |         values[e.key] = e.defaultValue; | ||||||
| @@ -245,8 +243,17 @@ class _GeneratedFormState extends State<GeneratedForm> { | |||||||
|     someValueChanged(isBuilding: true); |     someValueChanged(isBuilding: true); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   @override | ||||||
|  |   void initState() { | ||||||
|  |     super.initState(); | ||||||
|  |     initForm(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|  |     if (widget.key.toString() != initKey) { | ||||||
|  |       initForm(); | ||||||
|  |     } | ||||||
|     for (var r = 0; r < formInputs.length; r++) { |     for (var r = 0; r < formInputs.length; r++) { | ||||||
|       for (var e = 0; e < formInputs[r].length; e++) { |       for (var e = 0; e < formInputs[r].length; e++) { | ||||||
|         if (widget.items[r][e] is GeneratedFormSwitch) { |         if (widget.items[r][e] is GeneratedFormSwitch) { | ||||||
|   | |||||||
| @@ -327,6 +327,7 @@ class _AddAppPageState extends State<AddAppPage> { | |||||||
|                               height: 16, |                               height: 16, | ||||||
|                             ), |                             ), | ||||||
|                             GeneratedForm( |                             GeneratedForm( | ||||||
|  |                                 key: Key(pickedSource.runtimeType.toString()), | ||||||
|                                 items: pickedSource! |                                 items: pickedSource! | ||||||
|                                     .combinedAppSpecificSettingFormItems, |                                     .combinedAppSpecificSettingFormItems, | ||||||
|                                 onValueChanges: (values, valid, isBuilding) { |                                 onValueChanges: (values, valid, isBuilding) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user