@@ -8,10 +8,13 @@ import 'package:flutter_news_app/feature/data/model/categorynews/category_news_m
8
8
import 'package:flutter_news_app/feature/data/model/topheadlinesnews/top_headlines_news_response_model.dart' ;
9
9
import 'package:flutter_news_app/feature/presentation/bloc/topheadlinesnews/bloc.dart' ;
10
10
import 'package:flutter_news_app/feature/presentation/page/search/search_page.dart' ;
11
+ import 'package:flutter_news_app/feature/presentation/page/settings/settings_page.dart' ;
11
12
import 'package:flutter_news_app/feature/presentation/widget/widget_failure_message.dart' ;
12
13
import 'package:flutter_news_app/feature/presentation/widget/widget_item_news.dart' ;
13
14
import 'package:flutter_news_app/injection_container.dart' ;
14
15
import 'package:flutter_screenutil/flutter_screenutil.dart' ;
16
+ import 'package:hive/hive.dart' ;
17
+ import 'package:hive_flutter/hive_flutter.dart' ;
15
18
import 'package:intl/intl.dart' ;
16
19
import 'package:url_launcher/url_launcher.dart' ;
17
20
@@ -76,62 +79,87 @@ class _HomePageState extends State<HomePage> {
76
79
}
77
80
}
78
81
},
79
- child: Stack (
80
- children: [
81
- Container (
82
- width: double .infinity,
83
- height: double .infinity,
84
- color: Color (0xFFEFF5F5 ),
85
- ),
86
- SafeArea (
87
- child: Container (
88
- width: double .infinity,
89
- color: Color (0xFFEFF5F5 ),
90
- padding: EdgeInsets .symmetric (
91
- vertical: 24. h,
82
+ child: ValueListenableBuilder (
83
+ valueListenable: Hive .box ('settings' ).listenable (),
84
+ builder: (context, box, widget) {
85
+ var isDarkMode = box.get ('darkMode' ) ?? false ;
86
+ return Stack (
87
+ children: [
88
+ Container (
89
+ width: double .infinity,
90
+ height: double .infinity,
91
+ color: isDarkMode ? null : Color (0xFFEFF5F5 ),
92
92
),
93
- child: Column (
94
- crossAxisAlignment: CrossAxisAlignment .start,
95
- children: < Widget > [
96
- Padding (
97
- padding: EdgeInsets .symmetric (horizontal: 48. w),
98
- child: Row (
99
- children: < Widget > [
100
- Expanded (
101
- child: Text (
102
- 'Daily News' ,
103
- style: TextStyle (
104
- fontSize: 48. sp,
93
+ SafeArea (
94
+ child: Container (
95
+ width: double .infinity,
96
+ color: isDarkMode ? null : Color (0xFFEFF5F5 ),
97
+ padding: EdgeInsets .symmetric (
98
+ vertical: 24. h,
99
+ ),
100
+ child: Column (
101
+ crossAxisAlignment: CrossAxisAlignment .start,
102
+ children: < Widget > [
103
+ Padding (
104
+ padding: EdgeInsets .symmetric (horizontal: 48. w),
105
+ child: Row (
106
+ children: < Widget > [
107
+ Expanded (
108
+ child: Text (
109
+ 'Daily News' ,
110
+ style: TextStyle (
111
+ fontSize: 48. sp,
112
+ ),
113
+ ),
105
114
),
106
- ),
107
- ),
108
- GestureDetector (
109
- onTap: () {
110
- Navigator .push (
111
- context,
112
- MaterialPageRoute (builder: (context) => SearchPage ()),
113
- );
114
- },
115
- child: Hero (
116
- tag: 'iconSearch' ,
117
- child: Icon (Icons .search),
118
- ),
115
+ GestureDetector (
116
+ onTap: () {
117
+ Navigator .push (
118
+ context,
119
+ MaterialPageRoute (builder: (context) => SearchPage ()),
120
+ );
121
+ },
122
+ child: Hero (
123
+ tag: 'iconSearch' ,
124
+ child: Icon (
125
+ Icons .search,
126
+ size: 64. w,
127
+ ),
128
+ ),
129
+ ),
130
+ SizedBox (width: 48. w),
131
+ GestureDetector (
132
+ onTap: () {
133
+ Navigator .push (
134
+ context,
135
+ MaterialPageRoute (
136
+ builder: (context) => SettingsPage (),
137
+ ),
138
+ );
139
+ },
140
+ child: Icon (
141
+ Icons .settings,
142
+ size: 64. w,
143
+ ),
144
+ ),
145
+ ],
119
146
),
120
- ],
121
- ),
122
- ),
123
- WidgetDateToday (),
124
- SizedBox (height: 24. h),
125
- WidgetCategoryNews (listCategories: listCategories),
126
- SizedBox (height: 24. h),
127
- Expanded (
128
- child: Platform .isIOS ? _buildWidgetContentNewsIOS () : _buildWidgetContentNewsAndroid (),
147
+ ),
148
+ WidgetDateToday (),
149
+ SizedBox (height: 24. h),
150
+ WidgetCategoryNews (
151
+ listCategories: listCategories, indexDefaultSelected: indexCategorySelected),
152
+ SizedBox (height: 24. h),
153
+ Expanded (
154
+ child: Platform .isIOS ? _buildWidgetContentNewsIOS () : _buildWidgetContentNewsAndroid (),
155
+ ),
156
+ ],
129
157
),
130
- ] ,
158
+ ) ,
131
159
),
132
- ) ,
133
- ),
134
- ] ,
160
+ ] ,
161
+ );
162
+ } ,
135
163
),
136
164
),
137
165
),
@@ -404,8 +432,12 @@ class _HomePageState extends State<HomePage> {
404
432
405
433
class WidgetCategoryNews extends StatefulWidget {
406
434
final List <CategoryNewsModel > listCategories;
435
+ final int indexDefaultSelected;
407
436
408
- WidgetCategoryNews ({@required this .listCategories});
437
+ WidgetCategoryNews ({
438
+ @required this .listCategories,
439
+ @required this .indexDefaultSelected,
440
+ });
409
441
410
442
@override
411
443
_WidgetCategoryNewsState createState () => _WidgetCategoryNewsState ();
@@ -416,7 +448,7 @@ class _WidgetCategoryNewsState extends State<WidgetCategoryNews> {
416
448
417
449
@override
418
450
void initState () {
419
- indexCategorySelected = 0 ;
451
+ indexCategorySelected = widget.indexDefaultSelected ;
420
452
super .initState ();
421
453
}
422
454
@@ -439,12 +471,11 @@ class _WidgetCategoryNewsState extends State<WidgetCategoryNews> {
439
471
if (indexCategorySelected == index) {
440
472
return ;
441
473
}
442
- setState (() {
443
- indexCategorySelected = index;
444
- });
474
+ setState (() => indexCategorySelected = index);
445
475
var topHeadlinesNewsBloc = BlocProvider .of <TopHeadlinesNewsBloc >(context);
446
- topHeadlinesNewsBloc
447
- .add (ChangeCategoryTopHeadlinesNewsEvent (indexCategorySelected: indexCategorySelected));
476
+ topHeadlinesNewsBloc.add (
477
+ ChangeCategoryTopHeadlinesNewsEvent (indexCategorySelected: index),
478
+ );
448
479
},
449
480
child: Container (
450
481
child: AnimatedContainer (
0 commit comments