Skip to content

Commit dbe0296

Browse files
committed
refactor(app_configuration): replace SegmentedButton with TabBar for role selection
- Add TabController and TabBar to replace SegmentedButton for selecting user roles - Implement TabBarView to display role-specific fields - Adjust layout and spacing for improved usability - Update dispose method to include TabController disposal
1 parent aee7c25 commit dbe0296

File tree

1 file changed

+44
-45
lines changed

1 file changed

+44
-45
lines changed

lib/app_configuration/widgets/feed_decorator_form.dart

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ class FeedDecoratorForm extends StatefulWidget {
3131
State<FeedDecoratorForm> createState() => _FeedDecoratorFormState();
3232
}
3333

34-
class _FeedDecoratorFormState extends State<FeedDecoratorForm> {
35-
AppUserRole _selectedUserRole = AppUserRole.guestUser;
34+
class _FeedDecoratorFormState extends State<FeedDecoratorForm>
35+
with SingleTickerProviderStateMixin {
36+
late TabController _tabController;
3637
late final TextEditingController _itemsToDisplayController;
3738
late final Map<AppUserRole, TextEditingController> _roleControllers;
3839

3940
@override
4041
void initState() {
4142
super.initState();
43+
_tabController = TabController(length: AppUserRole.values.length, vsync: this);
4244
_initializeControllers();
4345
}
4446

@@ -54,30 +56,23 @@ class _FeedDecoratorFormState extends State<FeedDecoratorForm> {
5456
void _initializeControllers() {
5557
final decoratorConfig =
5658
widget.remoteConfig.feedDecoratorConfig[widget.decoratorType]!;
57-
_itemsToDisplayController =
58-
TextEditingController(
59-
text: decoratorConfig.itemsToDisplay?.toString() ?? '',
60-
)
61-
..selection = TextSelection.collapsed(
62-
offset: decoratorConfig.itemsToDisplay?.toString().length ?? 0,
63-
);
59+
_itemsToDisplayController = TextEditingController(
60+
text: decoratorConfig.itemsToDisplay?.toString() ?? '',
61+
)..selection = TextSelection.collapsed(
62+
offset: decoratorConfig.itemsToDisplay?.toString().length ?? 0,
63+
);
6464

6565
_roleControllers = {
6666
for (final role in AppUserRole.values)
67-
role:
68-
TextEditingController(
69-
text:
70-
decoratorConfig.visibleTo[role]?.daysBetweenViews
71-
.toString() ??
72-
'',
73-
)
74-
..selection = TextSelection.collapsed(
75-
offset:
76-
decoratorConfig.visibleTo[role]?.daysBetweenViews
77-
.toString()
78-
.length ??
79-
0,
80-
),
67+
role: TextEditingController(
68+
text: decoratorConfig.visibleTo[role]?.daysBetweenViews.toString() ??
69+
'',
70+
)..selection = TextSelection.collapsed(
71+
offset: decoratorConfig.visibleTo[role]?.daysBetweenViews
72+
.toString()
73+
.length ??
74+
0,
75+
),
8176
};
8277
}
8378

@@ -106,6 +101,7 @@ class _FeedDecoratorFormState extends State<FeedDecoratorForm> {
106101

107102
@override
108103
void dispose() {
104+
_tabController.dispose();
109105
_itemsToDisplayController.dispose();
110106
for (final controller in _roleControllers.values) {
111107
controller.dispose();
@@ -120,6 +116,7 @@ class _FeedDecoratorFormState extends State<FeedDecoratorForm> {
120116
widget.remoteConfig.feedDecoratorConfig[widget.decoratorType]!;
121117

122118
return Column(
119+
crossAxisAlignment: CrossAxisAlignment.start,
123120
children: [
124121
SwitchListTile(
125122
title: Text(l10n.enabledLabel),
@@ -159,37 +156,39 @@ class _FeedDecoratorFormState extends State<FeedDecoratorForm> {
159156
controller: _itemsToDisplayController,
160157
),
161158
const SizedBox(height: AppSpacing.lg),
159+
// Replaced SegmentedButton with TabBar for role selection
162160
Align(
163161
alignment: AlignmentDirectional.centerStart,
164-
child: SegmentedButton<AppUserRole>(
165-
style: SegmentedButton.styleFrom(
166-
shape: const RoundedRectangleBorder(
167-
borderRadius: BorderRadius.zero,
168-
),
162+
child: SizedBox(
163+
height: kTextTabBarHeight,
164+
child: TabBar(
165+
controller: _tabController,
166+
tabAlignment: TabAlignment.start,
167+
isScrollable: true,
168+
tabs: AppUserRole.values
169+
.map((role) => Tab(text: role.l10n(context)))
170+
.toList(),
169171
),
170-
segments: AppUserRole.values
172+
),
173+
),
174+
const SizedBox(height: AppSpacing.lg),
175+
// TabBarView to display role-specific fields
176+
SizedBox(
177+
height: 250, // Fixed height for TabBarView within a ListView
178+
child: TabBarView(
179+
controller: _tabController,
180+
children: AppUserRole.values
171181
.map(
172-
(role) => ButtonSegment<AppUserRole>(
173-
value: role,
174-
label: Text(role.l10n(context)),
182+
(role) => _buildRoleSpecificFields(
183+
context,
184+
l10n,
185+
role,
186+
decoratorConfig,
175187
),
176188
)
177189
.toList(),
178-
selected: {_selectedUserRole},
179-
onSelectionChanged: (newSelection) {
180-
setState(() {
181-
_selectedUserRole = newSelection.first;
182-
});
183-
},
184190
),
185191
),
186-
const SizedBox(height: AppSpacing.lg),
187-
_buildRoleSpecificFields(
188-
context,
189-
l10n,
190-
_selectedUserRole,
191-
decoratorConfig,
192-
),
193192
],
194193
);
195194
}

0 commit comments

Comments
 (0)