Created
September 28, 2019 17:58
-
-
Save divyanshub024/94ea6d227661a403c43ceb23dd95a960 to your computer and use it in GitHub Desktop.
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
import 'package:chitr/util/theme_notifier.dart'; | |
import 'package:chitr/values/strings.dart'; | |
import 'package:chitr/values/theme.dart'; | |
import 'package:day_night_switch/day_night_switch.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/widgets.dart'; | |
import 'package:provider/provider.dart'; | |
class SettingsPage extends StatefulWidget { | |
@override | |
_SettingsPageState createState() => _SettingsPageState(); | |
} | |
class _SettingsPageState extends State<SettingsPage> { | |
var _darkTheme = true; | |
@override | |
Widget build(BuildContext context) { | |
final themeNotifier = Provider.of<ThemeNotifier>(context); | |
_darkTheme = (themeNotifier.getTheme() == darkTheme); | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(Strings.titleSettings), | |
), | |
body: ListView( | |
children: <Widget>[ | |
ListTile( | |
title: Text('Dark Theme'), | |
contentPadding: const EdgeInsets.only(left: 16.0), | |
trailing: Transform.scale( | |
scale: 0.4, | |
child: DayNightSwitch( | |
value: _darkTheme, | |
onChanged: (val) { | |
setState(() { | |
_darkTheme = val; | |
}); | |
onThemeChanged(val, themeNotifier); | |
}, | |
), | |
), | |
) | |
], | |
), | |
); | |
} | |
void onThemeChanged(bool value, ThemeNotifier themeNotifier) { | |
(value) | |
? themeNotifier.setTheme(darkTheme) | |
: themeNotifier.setTheme(lightTheme); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment