Skip to content

Commit ad96696

Browse files
committed
feat(example): improve derived classifications UX
- KEEP card border around entire section - Remove expansion tile divider lines (top/bottom borders when expanded) - Add expandable descriptions for derived items - Filter out parent classification from children list - Prevent circular navigation to same page
1 parent d8e139e commit ad96696

File tree

2 files changed

+64
-22
lines changed

2 files changed

+64
-22
lines changed

app/example/lib/features/statistical_classifications/presentation/pages/statistical_classification_detail_page.dart

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,23 +346,31 @@ class _StatisticalClassificationDetailViewState
346346
) {
347347
final t = LocaleSettings.instance.currentTranslations;
348348

349-
if (state.items.isEmpty) {
350-
return SliverFillRemaining(
351-
child: Center(
349+
// Filter out parent classification from children list
350+
final filteredItems =
351+
state.items
352+
.where((item) => item.id != widget.classification.id)
353+
.toList();
354+
355+
if (filteredItems.isEmpty) {
356+
return SliverPadding(
357+
padding: const EdgeInsets.all(AppSizes.spaceMd),
358+
sliver: SliverToBoxAdapter(
352359
child: Column(
353360
mainAxisAlignment: MainAxisAlignment.center,
354361
children: [
355362
Icon(
356363
Icons.category_outlined,
357-
size: 64,
364+
size: 48,
358365
color: Theme.of(context).colorScheme.outline,
359366
),
360-
const Gap(AppSizes.spaceMd),
367+
const Gap(AppSizes.spaceSm),
361368
Text(
362369
t.statisticalClassifications.detail.noChildren,
363370
style: Theme.of(context).textTheme.titleMedium?.copyWith(
364371
color: Theme.of(context).colorScheme.onSurfaceVariant,
365372
),
373+
textAlign: TextAlign.center,
366374
),
367375
],
368376
),
@@ -380,7 +388,7 @@ class _StatisticalClassificationDetailViewState
380388
sliver: SliverList(
381389
delegate: SliverChildBuilderDelegate(
382390
(context, index) {
383-
if (index >= state.items.length) {
391+
if (index >= filteredItems.length) {
384392
return const Center(
385393
child: Padding(
386394
padding: EdgeInsets.all(AppSizes.spaceMd),
@@ -389,10 +397,10 @@ class _StatisticalClassificationDetailViewState
389397
);
390398
}
391399

392-
final child = state.items[index];
400+
final child = filteredItems[index];
393401
return _buildChildCard(context, child);
394402
},
395-
childCount: state.items.length + (state.isLoadingMore ? 1 : 0),
403+
childCount: filteredItems.length + (state.isLoadingMore ? 1 : 0),
396404
),
397405
),
398406
);

app/example/lib/features/statistical_classifications/presentation/widgets/derived_classifications_section.dart

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class DerivedClassificationsSection extends StatelessWidget {
3030
),
3131
),
3232
child: ExpansionTile(
33+
shape: const Border(),
34+
collapsedShape: const Border(),
3335
leading: Icon(
3436
Icons.account_tree_outlined,
3537
color: theme.colorScheme.primary,
@@ -45,7 +47,6 @@ class DerivedClassificationsSection extends StatelessWidget {
4547
style: theme.textTheme.bodySmall,
4648
),
4749
children: [
48-
const Divider(height: 1),
4950
ListView.separated(
5051
shrinkWrap: true,
5152
physics: const NeverScrollableScrollPhysics(),
@@ -63,16 +64,26 @@ class DerivedClassificationsSection extends StatelessWidget {
6364
}
6465
}
6566

66-
class _DerivedClassificationItem extends StatelessWidget {
67+
class _DerivedClassificationItem extends StatefulWidget {
6768
const _DerivedClassificationItem({
6869
required this.item,
6970
});
7071

7172
final ClassificationItem item;
7273

74+
@override
75+
State<_DerivedClassificationItem> createState() =>
76+
_DerivedClassificationItemState();
77+
}
78+
79+
class _DerivedClassificationItemState
80+
extends State<_DerivedClassificationItem> {
81+
bool _isExpanded = false;
82+
7383
@override
7484
Widget build(BuildContext context) {
7585
final theme = Theme.of(context);
86+
final t = LocaleSettings.instance.currentTranslations;
7687

7788
return Container(
7889
padding: const EdgeInsets.all(AppSizes.spaceSm),
@@ -81,9 +92,6 @@ class _DerivedClassificationItem extends StatelessWidget {
8192
alpha: 0.3,
8293
),
8394
borderRadius: BorderRadius.circular(AppSizes.radiusSm),
84-
border: Border.all(
85-
color: theme.colorScheme.outline.withValues(alpha: 0.2),
86-
),
8795
),
8896
child: Column(
8997
crossAxisAlignment: CrossAxisAlignment.start,
@@ -100,7 +108,7 @@ class _DerivedClassificationItem extends StatelessWidget {
100108
borderRadius: BorderRadius.circular(AppSizes.radiusXs),
101109
),
102110
child: Text(
103-
item.code,
111+
widget.item.code,
104112
style: theme.textTheme.labelSmall?.copyWith(
105113
color: theme.colorScheme.onPrimaryContainer,
106114
fontWeight: FontWeight.bold,
@@ -111,7 +119,7 @@ class _DerivedClassificationItem extends StatelessWidget {
111119
const Gap(AppSizes.spaceXs),
112120
Expanded(
113121
child: Text(
114-
item.title,
122+
widget.item.title,
115123
style: theme.textTheme.titleSmall?.copyWith(
116124
fontWeight: FontWeight.w600,
117125
),
@@ -121,16 +129,42 @@ class _DerivedClassificationItem extends StatelessWidget {
121129
),
122130
],
123131
),
124-
if (item.description.isNotEmpty) ...[
132+
if (widget.item.description.isNotEmpty) ...[
125133
const Gap(AppSizes.spaceXs),
126-
Text(
127-
item.description,
128-
style: theme.textTheme.bodySmall?.copyWith(
129-
color: theme.colorScheme.onSurfaceVariant,
134+
GestureDetector(
135+
onTap: () {
136+
setState(() {
137+
_isExpanded = !_isExpanded;
138+
});
139+
},
140+
child: Text(
141+
widget.item.description,
142+
style: theme.textTheme.bodySmall?.copyWith(
143+
color: theme.colorScheme.onSurfaceVariant,
144+
),
145+
maxLines: _isExpanded ? null : 3,
146+
overflow:
147+
_isExpanded ? TextOverflow.visible : TextOverflow.ellipsis,
130148
),
131-
maxLines: 3,
132-
overflow: TextOverflow.ellipsis,
133149
),
150+
if (widget.item.description.length > 150)
151+
GestureDetector(
152+
onTap: () {
153+
setState(() {
154+
_isExpanded = !_isExpanded;
155+
});
156+
},
157+
child: Padding(
158+
padding: const EdgeInsets.only(top: 4),
159+
child: Text(
160+
_isExpanded ? t.common.showLess : t.common.showMore,
161+
style: theme.textTheme.labelSmall?.copyWith(
162+
color: theme.colorScheme.primary,
163+
fontWeight: FontWeight.w600,
164+
),
165+
),
166+
),
167+
),
134168
],
135169
],
136170
),

0 commit comments

Comments
 (0)