-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
232 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_news_app/feature/presentation/page/home/home_page.dart'; | ||
import 'package:hive/hive.dart'; | ||
import 'package:hive_flutter/hive_flutter.dart'; | ||
|
||
class App extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
debugShowCheckedModeBanner: false, | ||
title: 'News App', | ||
home: HomePage(), | ||
return ValueListenableBuilder( | ||
valueListenable: Hive.box('settings').listenable(), | ||
builder: (context, box, widget) { | ||
var isDarkMode = box.get('darkMode') ?? false; | ||
return MaterialApp( | ||
debugShowCheckedModeBanner: false, | ||
title: 'News App', | ||
theme: ThemeData( | ||
brightness: isDarkMode ? Brightness.dark : Brightness.light, | ||
), | ||
home: HomePage(), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_screenutil/flutter_screenutil.dart'; | ||
import 'package:hive/hive.dart'; | ||
import 'package:hive_flutter/hive_flutter.dart'; | ||
|
||
class SettingsPage extends StatefulWidget { | ||
@override | ||
_SettingsPageState createState() => _SettingsPageState(); | ||
} | ||
|
||
class _SettingsPageState extends State<SettingsPage> { | ||
@override | ||
Widget build(BuildContext context) { | ||
ScreenUtil.init(context); | ||
return Scaffold( | ||
appBar: WidgetAppBar(), | ||
body: Container( | ||
width: double.infinity, | ||
padding: EdgeInsets.all(48.w), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: <Widget>[ | ||
Text( | ||
'Interface', | ||
style: TextStyle( | ||
fontSize: 48.sp, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
Row( | ||
children: <Widget>[ | ||
Expanded( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: <Widget>[ | ||
Text( | ||
'Use dark mode', | ||
style: TextStyle( | ||
fontSize: 42.sp, | ||
), | ||
), | ||
Text( | ||
'Get that whiteness out', | ||
style: TextStyle( | ||
fontSize: 36.sp, | ||
color: Colors.grey, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
ValueListenableBuilder( | ||
valueListenable: Hive.box('settings').listenable(), | ||
builder: (context, box, widget) { | ||
var isDarkMode = box.get('darkMode') ?? false; | ||
return Switch( | ||
value: isDarkMode, | ||
onChanged: (value) async { | ||
isDarkMode = value; | ||
await box.put('darkMode', isDarkMode); | ||
}, | ||
); | ||
}, | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class WidgetAppBar extends PreferredSize { | ||
@override | ||
Widget build(BuildContext context) { | ||
return ValueListenableBuilder( | ||
valueListenable: Hive.box('settings').listenable(), | ||
builder: (context, box, widget) { | ||
var isDarkMode = box.get('darkMode') ?? false; | ||
return isDarkMode | ||
? AppBar( | ||
title: Text('Settings'), | ||
) | ||
: AppBar( | ||
title: Text('Settings'), | ||
); | ||
}, | ||
); | ||
} | ||
|
||
@override | ||
Size get preferredSize { | ||
return Size.fromHeight(kToolbarHeight); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.