Skip to content

Commit f154623

Browse files
committed
feat(content): content management page
- Added tab controller - Added bloc listener - Added floating action button
1 parent 84a311d commit f154623

File tree

1 file changed

+72
-38
lines changed

1 file changed

+72
-38
lines changed

lib/content_management/view/content_management_page.dart

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_bloc/flutter_bloc.dart';
3+
import 'package:go_router/go_router.dart';
4+
import 'package:ht_dashboard/content_management/bloc/content_management_bloc.dart';
25
import 'package:ht_dashboard/content_management/view/categories_page.dart';
36
import 'package:ht_dashboard/content_management/view/headlines_page.dart';
47
import 'package:ht_dashboard/content_management/view/sources_page.dart';
58
import 'package:ht_dashboard/l10n/l10n.dart';
9+
import 'package:ht_dashboard/router/routes.dart';
610
import 'package:ht_dashboard/shared/constants/app_spacing.dart';
711

812
/// {@template content_management_page}
@@ -24,59 +28,89 @@ class _ContentManagementPageState extends State<ContentManagementPage>
2428
void initState() {
2529
super.initState();
2630
_tabController = TabController(length: 3, vsync: this);
31+
_tabController.addListener(_onTabChanged);
2732
}
2833

2934
@override
3035
void dispose() {
36+
_tabController.removeListener(_onTabChanged);
3137
_tabController.dispose();
3238
super.dispose();
3339
}
3440

41+
void _onTabChanged() {
42+
if (!_tabController.indexIsChanging) {
43+
final tab = ContentManagementTab.values[_tabController.index];
44+
context.read<ContentManagementBloc>().add(ContentManagementTabChanged(tab));
45+
}
46+
}
47+
3548
@override
3649
Widget build(BuildContext context) {
3750
final l10n = context.l10n;
38-
return Scaffold(
39-
appBar: AppBar(
40-
title: Text(l10n.contentManagement),
41-
bottom: PreferredSize(
42-
preferredSize: const Size.fromHeight(kTextTabBarHeight + AppSpacing.lg),
43-
child: Column(
44-
crossAxisAlignment: CrossAxisAlignment.start,
45-
children: [
46-
Padding(
47-
padding: const EdgeInsets.only(
48-
left: AppSpacing.lg,
49-
right: AppSpacing.lg,
50-
bottom: AppSpacing.lg,
51-
),
52-
child: Text(
53-
l10n.contentManagementPageDescription,
54-
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
55-
color: Theme.of(context).colorScheme.onSurfaceVariant,
51+
return BlocListener<ContentManagementBloc, ContentManagementState>(
52+
listener: (context, state) {
53+
// Optionally handle state changes, e.g., show snackbar for errors
54+
},
55+
child: Scaffold(
56+
appBar: AppBar(
57+
title: Text(l10n.contentManagement),
58+
bottom: PreferredSize(
59+
preferredSize:
60+
const Size.fromHeight(kTextTabBarHeight + AppSpacing.lg),
61+
child: Column(
62+
crossAxisAlignment: CrossAxisAlignment.start,
63+
children: [
64+
Padding(
65+
padding: const EdgeInsets.only(
66+
left: AppSpacing.lg,
67+
right: AppSpacing.lg,
68+
bottom: AppSpacing.lg,
69+
),
70+
child: Text(
71+
l10n.contentManagementPageDescription,
72+
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
73+
color: Theme.of(context).colorScheme.onSurfaceVariant,
74+
),
5675
),
5776
),
58-
),
59-
TabBar(
60-
controller: _tabController,
61-
tabAlignment: TabAlignment.start,
62-
isScrollable: true,
63-
tabs: [
64-
Tab(text: l10n.headlines),
65-
Tab(text: l10n.categories),
66-
Tab(text: l10n.sources),
67-
],
68-
),
69-
],
77+
TabBar(
78+
controller: _tabController,
79+
tabAlignment: TabAlignment.start,
80+
isScrollable: true,
81+
tabs: [
82+
Tab(text: l10n.headlines),
83+
Tab(text: l10n.categories),
84+
Tab(text: l10n.sources),
85+
],
86+
),
87+
],
88+
),
7089
),
7190
),
72-
),
73-
body: TabBarView(
74-
controller: _tabController,
75-
children: const [
76-
HeadlinesPage(),
77-
CategoriesPage(),
78-
SourcesPage(),
79-
],
91+
body: TabBarView(
92+
controller: _tabController,
93+
children: const [
94+
HeadlinesPage(),
95+
CategoriesPage(),
96+
SourcesPage(),
97+
],
98+
),
99+
floatingActionButton: FloatingActionButton(
100+
onPressed: () {
101+
final currentTab =
102+
context.read<ContentManagementBloc>().state.activeTab;
103+
switch (currentTab) {
104+
case ContentManagementTab.headlines:
105+
context.goNamed(Routes.createHeadlineName);
106+
case ContentManagementTab.categories:
107+
context.goNamed(Routes.createCategoryName);
108+
case ContentManagementTab.sources:
109+
context.goNamed(Routes.createSourceName);
110+
}
111+
},
112+
child: const Icon(Icons.add),
113+
),
80114
),
81115
);
82116
}

0 commit comments

Comments
 (0)