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