[SYNC]
This commit is contained in:
@@ -315,53 +315,52 @@ class AstromicFormController extends FormController {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
void initializeFormGroup(FormGroupStructure groupStructure, {int initialCount = 1}) {
|
void initializeFormGroup(FormGroupStructure groupStructure, {int initialCount = 1}) {
|
||||||
assert(groupStructure.fields.isNotEmpty, '${groupStructure.id}: Group fields should NOT be empty.');
|
assert(groupStructure.fields.isNotEmpty, '${groupStructure.id}: Group fields should NOT be empty.');
|
||||||
|
|
||||||
// Validate subgroups (if any)
|
// Validate subgroups (if any)
|
||||||
_validateSubGroups(groupStructure);
|
_validateSubGroups(groupStructure);
|
||||||
|
|
||||||
// Add structure to registry
|
// Add structure to registry
|
||||||
_formGroups.add(groupStructure);
|
_formGroups.add(groupStructure);
|
||||||
|
|
||||||
// Initialize the group instances
|
// Initialize the group instances
|
||||||
_initializeGroupControllers(groupStructure, initialCount);
|
_initializeGroupControllers(groupStructure, initialCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively initialize controllers for the group and its subgroups
|
/// Recursively initialize controllers for the group and its subgroups
|
||||||
void _initializeGroupControllers(FormGroupStructure groupStructure, int initialCount, {String parentPrefix = ''}) {
|
void _initializeGroupControllers(FormGroupStructure groupStructure, int initialCount, {String parentPrefix = ''}) {
|
||||||
// Add main group fields/values
|
// Add main group fields/values
|
||||||
for (int groupIndex = 0; groupIndex < initialCount; groupIndex++) {
|
for (int groupIndex = 0; groupIndex < initialCount; groupIndex++) {
|
||||||
_addGroupControllers(groupStructure, groupIndex, parentPrefix: parentPrefix);
|
_addGroupControllers(groupStructure, groupIndex, parentPrefix: parentPrefix);
|
||||||
|
|
||||||
// Recursively handle subgroups
|
// Recursively handle subgroups
|
||||||
if (groupStructure.subGroups != null && groupStructure.subGroups!.isNotEmpty) {
|
if (groupStructure.subGroups != null && groupStructure.subGroups!.isNotEmpty) {
|
||||||
for (final (FormGroupStructure subGroup, int subgroupInitialCount) in groupStructure.subGroups!) {
|
for (final (FormGroupStructure subGroup, int subgroupInitialCount) in groupStructure.subGroups!) {
|
||||||
final String subgroupPrefix = parentPrefix.isEmpty
|
final String subgroupPrefix = parentPrefix.isEmpty
|
||||||
? standeredGroupFormat(groupStructure.id, groupIndex, subGroup.id)
|
? standeredGroupFormat(groupStructure.id, groupIndex, subGroup.id)
|
||||||
: '$parentPrefix->${standeredGroupFormat(groupStructure.id, groupIndex, subGroup.id)}'; // Add to parentPrefix only once
|
: '$parentPrefix->${standeredGroupFormat(groupStructure.id, groupIndex, subGroup.id)}'; // Add to parentPrefix only once
|
||||||
|
|
||||||
// Initialize subgroup controllers recursively
|
// Initialize subgroup controllers recursively
|
||||||
for (int subIndex = 0; subIndex < subgroupInitialCount; subIndex++) {
|
for (int subIndex = 0; subIndex < subgroupInitialCount; subIndex++) {
|
||||||
_initializeGroupControllers(subGroup, subgroupInitialCount, parentPrefix: subgroupPrefix);
|
_initializeGroupControllers(subGroup, subgroupInitialCount, parentPrefix: subgroupPrefix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Validate subgroups recursively
|
/// Validate subgroups recursively
|
||||||
void _validateSubGroups(FormGroupStructure groupStructure) {
|
void _validateSubGroups(FormGroupStructure groupStructure) {
|
||||||
groupStructure.subGroups?.forEach((subGroupTuple) {
|
groupStructure.subGroups?.forEach((subGroupTuple) {
|
||||||
final subGroup = subGroupTuple.$1;
|
final subGroup = subGroupTuple.$1;
|
||||||
assert(subGroup.fields.isNotEmpty, '${subGroup.id}: Subgroup fields should NOT be empty.');
|
assert(subGroup.fields.isNotEmpty, '${subGroup.id}: Subgroup fields should NOT be empty.');
|
||||||
|
|
||||||
// Recursively validate subgroups of subgroups
|
|
||||||
if (subGroup.subGroups != null) {
|
|
||||||
_validateSubGroups(subGroup);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Recursively validate subgroups of subgroups
|
||||||
|
if (subGroup.subGroups != null) {
|
||||||
|
_validateSubGroups(subGroup);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// void initializeFormGroup(FormGroupStructure groupStructure, {int initialCount = 1}) {
|
// void initializeFormGroup(FormGroupStructure groupStructure, {int initialCount = 1}) {
|
||||||
// assert(groupStructure.fields.isNotEmpty, '$groupStructure: Group Fields should NOT be empty.');
|
// assert(groupStructure.fields.isNotEmpty, '$groupStructure: Group Fields should NOT be empty.');
|
||||||
|
|||||||
@@ -1,132 +1,132 @@
|
|||||||
//s1 Imports
|
// //s1 Imports
|
||||||
//s2 Packages
|
// //s2 Packages
|
||||||
//s3 Core Packages
|
// //s3 Core Packages
|
||||||
import 'package:flutter/material.dart';
|
// import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../../astromic_helpers.dart';
|
// import '../../../astromic_helpers.dart';
|
||||||
//s3 Internal Packages
|
// //s3 Internal Packages
|
||||||
// import 'package:astromic_elements/astromic_elements.dart';
|
// // import 'package:astromic_elements/astromic_elements.dart';
|
||||||
//s3 3rd-party Packages
|
// //s3 3rd-party Packages
|
||||||
//s2 Utility
|
// //s2 Utility
|
||||||
//s3 Configs
|
// //s3 Configs
|
||||||
// import '../../../../../core/configs/routing/routing.config.dart';
|
// // import '../../../../../core/configs/routing/routing.config.dart';
|
||||||
//s3 Misc
|
// //s3 Misc
|
||||||
//s2 Domain
|
// //s2 Domain
|
||||||
//s3 Entities
|
// //s3 Entities
|
||||||
//s3 Usecases
|
// //s3 Usecases
|
||||||
//s2 Presentation
|
// //s2 Presentation
|
||||||
//s3 Design
|
// //s3 Design
|
||||||
// import '../../../../design-system/design_system.dart';
|
// // import '../../../../design-system/design_system.dart';
|
||||||
//s3 Presenters
|
// //s3 Presenters
|
||||||
//s3 Widgets
|
// //s3 Widgets
|
||||||
//s1 Exports
|
// //s1 Exports
|
||||||
|
|
||||||
class FormGroupWrapper extends StatefulWidget {
|
// class FormGroupWrapper extends StatefulWidget {
|
||||||
//SECTION - Widget Arguments
|
// //SECTION - Widget Arguments
|
||||||
final AstromicFormController formController;
|
// final AstromicFormController formController;
|
||||||
final String groupID;
|
// final String groupID;
|
||||||
final Widget Function(List<Widget> children, String Function() addItem, void Function(int) removeItem) groupBuilder;
|
// final Widget Function(List<Widget> children, String Function() addItem, void Function(int) removeItem) groupBuilder;
|
||||||
final Widget Function(int index, String composedID, VoidCallback removeItem) itemBuilder;
|
// final Widget Function(int index, String composedID, VoidCallback removeItem) itemBuilder;
|
||||||
final int startLength;
|
// final int startLength;
|
||||||
final bool isSubGroup;
|
// final bool isSubGroup;
|
||||||
//!SECTION
|
// //!SECTION
|
||||||
//
|
// //
|
||||||
const FormGroupWrapper({
|
// const FormGroupWrapper({
|
||||||
super.key,
|
// super.key,
|
||||||
required this.formController,
|
// required this.formController,
|
||||||
required this.groupID,
|
// required this.groupID,
|
||||||
required this.groupBuilder,
|
// required this.groupBuilder,
|
||||||
required this.itemBuilder,
|
// required this.itemBuilder,
|
||||||
this.isSubGroup = false,
|
// this.isSubGroup = false,
|
||||||
this.startLength = 0,
|
// this.startLength = 0,
|
||||||
});
|
// });
|
||||||
|
|
||||||
@override
|
// @override
|
||||||
State<FormGroupWrapper> createState() => _FormGroupWrapperState();
|
// State<FormGroupWrapper> createState() => _FormGroupWrapperState();
|
||||||
}
|
// }
|
||||||
|
|
||||||
class _FormGroupWrapperState extends State<FormGroupWrapper> {
|
// class _FormGroupWrapperState extends State<FormGroupWrapper> {
|
||||||
//
|
// //
|
||||||
//SECTION - State Variables
|
// //SECTION - State Variables
|
||||||
//s1 --State
|
// //s1 --State
|
||||||
late List<FormGroupInstance> instances;
|
// late List<FormGroupInstance> instances;
|
||||||
//s1 --State
|
// //s1 --State
|
||||||
//
|
// //
|
||||||
//s1 --Controllers
|
// //s1 --Controllers
|
||||||
//s1 --Controllers
|
// //s1 --Controllers
|
||||||
//
|
// //
|
||||||
//s1 --Constants
|
// //s1 --Constants
|
||||||
//s1 --Constants
|
// //s1 --Constants
|
||||||
//!SECTION
|
// //!SECTION
|
||||||
|
|
||||||
@override
|
// @override
|
||||||
void initState() {
|
// void initState() {
|
||||||
super.initState();
|
// super.initState();
|
||||||
//
|
// //
|
||||||
//SECTION - State Variables initializations & Listeners
|
// //SECTION - State Variables initializations & Listeners
|
||||||
//s1 --State
|
// //s1 --State
|
||||||
//s1 --State
|
// //s1 --State
|
||||||
//
|
// //
|
||||||
//s1 --Controllers & Listeners
|
// //s1 --Controllers & Listeners
|
||||||
instances = widget.formController.getFormGroupValue(widget.groupID, isSubGroup: widget.isSubGroup)!.instances;
|
// instances = widget.formController.getFormGroupValue(widget.groupID, isSubGroup: widget.isSubGroup)!.instances;
|
||||||
//s1 --Controllers & Listeners
|
// //s1 --Controllers & Listeners
|
||||||
//
|
// //
|
||||||
//s1 --Late & Async Initializers
|
// //s1 --Late & Async Initializers
|
||||||
//s1 --Late & Async Initializers
|
// //s1 --Late & Async Initializers
|
||||||
//!SECTION
|
// //!SECTION
|
||||||
}
|
// }
|
||||||
|
|
||||||
//SECTION - Dumb Widgets
|
// //SECTION - Dumb Widgets
|
||||||
//!SECTION
|
// //!SECTION
|
||||||
|
|
||||||
//SECTION - Stateless functions
|
// //SECTION - Stateless functions
|
||||||
//!SECTION
|
// //!SECTION
|
||||||
|
|
||||||
//SECTION - Action Callbacks
|
// //SECTION - Action Callbacks
|
||||||
//!SECTION
|
// //!SECTION
|
||||||
|
|
||||||
@override
|
// @override
|
||||||
Widget build(BuildContext context) {
|
// Widget build(BuildContext context) {
|
||||||
//SECTION - Build Setup
|
// //SECTION - Build Setup
|
||||||
//s1 --Values
|
// //s1 --Values
|
||||||
//double w = MediaQuery.of(context).size.width;
|
// //double w = MediaQuery.of(context).size.width;
|
||||||
//double h = MediaQuery.of(context).size.height;
|
// //double h = MediaQuery.of(context).size.height;
|
||||||
//s1 --Values
|
// //s1 --Values
|
||||||
//
|
// //
|
||||||
//s1 --Contexted Widgets
|
// //s1 --Contexted Widgets
|
||||||
//s1 --Contexted Widgets
|
// //s1 --Contexted Widgets
|
||||||
//!SECTION
|
// //!SECTION
|
||||||
|
|
||||||
//SECTION - Build Return
|
// //SECTION - Build Return
|
||||||
return widget.groupBuilder(
|
// return widget.groupBuilder(
|
||||||
// Children
|
// // Children
|
||||||
List<Widget>.generate(instances.length, (int i) => widget.itemBuilder(i, instances[i].composedID, () => _removeItem(i))),
|
// List<Widget>.generate(instances.length, (int i) => widget.itemBuilder(i, instances[i].composedID, () => _removeItem(i))),
|
||||||
// Add Callback
|
// // Add Callback
|
||||||
() {
|
// () {
|
||||||
String id = '';
|
// String id = '';
|
||||||
setState(() {
|
// setState(() {
|
||||||
// id = widget.formController.addInstanceToFormGroup(widget.groupID,isSubGroup: widget.isSubGroup);
|
// // id = widget.formController.addInstanceToFormGroup(widget.groupID,isSubGroup: widget.isSubGroup);
|
||||||
// instances = widget.formController.getFormGroupValue(widget.groupID,isSubGroup: widget.isSubGroup)!.instances;
|
// // instances = widget.formController.getFormGroupValue(widget.groupID,isSubGroup: widget.isSubGroup)!.instances;
|
||||||
});
|
// });
|
||||||
return id;
|
// return id;
|
||||||
},
|
// },
|
||||||
// Remove Callback
|
// // Remove Callback
|
||||||
(int i) => _removeItem(i),
|
// (int i) => _removeItem(i),
|
||||||
);
|
// );
|
||||||
//!SECTION
|
// //!SECTION
|
||||||
}
|
// }
|
||||||
|
|
||||||
void _removeItem(int i) {
|
// void _removeItem(int i) {
|
||||||
setState(() {
|
// setState(() {
|
||||||
// widget.formController.removeInstanceFromFormGroup(widget.groupID, i,isSubGroup: widget.isSubGroup);
|
// // widget.formController.removeInstanceFromFormGroup(widget.groupID, i,isSubGroup: widget.isSubGroup);
|
||||||
// instances = widget.formController.getFormGroupValue(widget.groupID,isSubGroup: widget.isSubGroup)!.instances;
|
// // instances = widget.formController.getFormGroupValue(widget.groupID,isSubGroup: widget.isSubGroup)!.instances;
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
@override
|
// @override
|
||||||
void dispose() {
|
// void dispose() {
|
||||||
//SECTION - Disposable variables
|
// //SECTION - Disposable variables
|
||||||
//!SECTION
|
// //!SECTION
|
||||||
super.dispose();
|
// super.dispose();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user