1
1
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' ;
2
5
import 'package:ht_dashboard/content_management/view/categories_page.dart' ;
3
6
import 'package:ht_dashboard/content_management/view/headlines_page.dart' ;
4
7
import 'package:ht_dashboard/content_management/view/sources_page.dart' ;
5
8
import 'package:ht_dashboard/l10n/l10n.dart' ;
9
+ import 'package:ht_dashboard/router/routes.dart' ;
6
10
import 'package:ht_dashboard/shared/constants/app_spacing.dart' ;
7
11
8
12
/// {@template content_management_page}
@@ -24,59 +28,89 @@ class _ContentManagementPageState extends State<ContentManagementPage>
24
28
void initState () {
25
29
super .initState ();
26
30
_tabController = TabController (length: 3 , vsync: this );
31
+ _tabController.addListener (_onTabChanged);
27
32
}
28
33
29
34
@override
30
35
void dispose () {
36
+ _tabController.removeListener (_onTabChanged);
31
37
_tabController.dispose ();
32
38
super .dispose ();
33
39
}
34
40
41
+ void _onTabChanged () {
42
+ if (! _tabController.indexIsChanging) {
43
+ final tab = ContentManagementTab .values[_tabController.index];
44
+ context.read <ContentManagementBloc >().add (ContentManagementTabChanged (tab));
45
+ }
46
+ }
47
+
35
48
@override
36
49
Widget build (BuildContext context) {
37
50
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
+ ),
56
75
),
57
76
),
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
+ ) ,
70
89
),
71
90
),
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
+ ),
80
114
),
81
115
);
82
116
}
0 commit comments