-
-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FormBuilder and Tabbed/Paged forms #1426
Comments
Related: #1366 |
Basically, as soon as tabs/pages are added to form, it will stop working and submitting all fields (unless user clicked all tabs manually). The problem is on intersection of two issues:
I could not find any decent solution for 1. What people seem to be doing is doing hacks with animating to each tab and showing it upon initialization. Even creating packages for that. |
If anyone is interested for workaround for tabbed forms, here is a version of tabbar that works for me (it uses IndexedStack to show all the tabs): class FormTabBar extends StatefulWidget {
final List<String> keys;
final List<Widget> pages;
const FormTabBar({required this.keys, required this.pages, super.key})
: assert(keys.length == pages.length,
'keys and pages must have the same length');
@override
State<FormTabBar> createState() => _FormTabBarState();
}
class _FormTabBarState extends State<FormTabBar>
with SingleTickerProviderStateMixin {
TabController? _tabController;
@override
initState() {
super.initState();
_tabController = TabController(length: widget.keys.length, vsync: this);
}
@override
dispose() {
_tabController!.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
TabBar(
controller: _tabController,
isScrollable: false,
indicatorSize: TabBarIndicatorSize.tab,
tabs: widget.keys.map((e) => Tab(text: e)).toList(growable: false),
onTap: (index) {
setState(() {
_tabController!.index = index;
});
},
),
Expanded(
child: IndexedStack(
index: _tabController!.index,
children: widget.pages,
),
),
],
);
}
} |
Actually same goes while using the ListView.builder widget for form widgets. For this I added cacheExtent: 1000, so all the form widgets are rendered |
Is there an existing issue for this?
Package/Plugin version
9.4.1
Platforms
Flutter doctor
Flutter doctor
Minimal code example
Current Behavior
The issue is well described here: #462
As form grows, it's natural to split fields into few tabs/pages. As soon as it's happens (using default Flutter widgets), fields in the "hidden" tabs/pages aren't initialized. When form is submitted, these fields are absent, which is incorrect behavior.
Expected Behavior
There is a solution to use tabbed forms with FormBuilder.
It's more likely could be another way to initialize fields with initial values.
Steps To Reproduce
Run code as described
Aditional information
No response
The text was updated successfully, but these errors were encountered: