This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/pages/settings/lookandfeel_settings.part.dart

147 lines
4.5 KiB
Dart
Raw Normal View History

2020-04-11 19:09:35 +03:00
part of '../../main.dart';
class LookAndFeelSettingsPage extends StatefulWidget {
LookAndFeelSettingsPage({Key key, this.title}) : super(key: key);
final String title;
@override
_LookAndFeelSettingsPageState createState() => new _LookAndFeelSettingsPageState();
}
class _LookAndFeelSettingsPageState extends State<LookAndFeelSettingsPage> {
AppTheme _currentTheme;
2020-05-09 21:08:42 +03:00
bool _scrollBadges = false;
2020-05-29 21:16:59 +03:00
DisplayMode _displayMode;
2020-04-11 19:09:35 +03:00
@override
void initState() {
super.initState();
_loadSettings();
}
_loadSettings() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.reload();
SharedPreferences.getInstance().then((prefs) {
setState(() {
2020-05-29 21:16:59 +03:00
_currentTheme = AppTheme.values[prefs.getInt('app-theme') ?? AppTheme.defaultTheme.index];
_displayMode = DisplayMode.values[prefs.getInt('display-mode') ?? DisplayMode.normal.index];
2020-05-09 21:08:42 +03:00
_scrollBadges = prefs.getBool('scroll-badges') ?? true;
2020-04-11 19:09:35 +03:00
});
});
}
2020-05-09 21:08:42 +03:00
_saveTheme(AppTheme theme) {
2020-04-11 19:09:35 +03:00
SharedPreferences.getInstance().then((prefs) {
prefs.setInt('app-theme', theme.index);
2020-05-09 21:08:42 +03:00
prefs.setBool('scroll-badges', _scrollBadges);
2020-04-11 19:09:35 +03:00
setState(() {
_currentTheme = theme;
eventBus.fire(ChangeThemeEvent(_currentTheme));
});
});
}
2020-05-29 21:16:59 +03:00
Future _saveBadgesSettings() async {
2020-05-09 21:08:42 +03:00
SharedPreferences prefs = await SharedPreferences.getInstance();
2020-05-13 15:46:25 +03:00
AppSettings().scrollBadges = _scrollBadges;
2020-05-09 21:08:42 +03:00
await prefs.setBool('scroll-badges', _scrollBadges);
}
2020-05-29 21:16:59 +03:00
Future _saveDisplayMode(DisplayMode mode) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
AppSettings().displayMode = mode;
await prefs.setInt('display-mode', mode.index);
if (mode == DisplayMode.fullscreen) {
SystemChrome.setEnabledSystemUIOverlays([]);
} else {
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
}
}
2020-04-11 19:09:35 +03:00
Map appThemeName = {
AppTheme.defaultTheme: 'Default',
AppTheme.haTheme: 'Home Assistant theme',
AppTheme.darkTheme: 'Dark theme'
};
2020-05-29 21:16:59 +03:00
Map DisplayModeName = {
DisplayMode.normal: 'Normal',
DisplayMode.fullscreen: 'Fullscreen'
};
2020-04-11 19:09:35 +03:00
@override
Widget build(BuildContext context) {
return ListView(
scrollDirection: Axis.vertical,
padding: const EdgeInsets.all(20.0),
children: <Widget>[
2020-04-11 19:55:50 +03:00
Text("Application theme:", style: Theme.of(context).textTheme.body2),
2020-04-11 19:09:35 +03:00
Container(height: Sizes.rowPadding),
DropdownButton<AppTheme>(
value: _currentTheme,
iconSize: 30.0,
isExpanded: true,
style: Theme.of(context).textTheme.title,
items: AppTheme.values.map((value) {
return new DropdownMenuItem<AppTheme>(
value: value,
child: Text('${appThemeName[value]}'),
);
}).toList(),
2020-05-09 21:08:42 +03:00
onChanged: (theme) => _saveTheme(theme),
),
Container(height: Sizes.doubleRowPadding),
Text("Badges display:", style: Theme.of(context).textTheme.body2),
Container(height: Sizes.rowPadding),
DropdownButton<bool>(
value: _scrollBadges,
iconSize: 30.0,
isExpanded: true,
style: Theme.of(context).textTheme.title,
items: [true, false].map((value) {
return new DropdownMenuItem<bool>(
value: value,
child: Text('${value ? 'Horizontal scroll' : 'In rows'}'),
);
}).toList(),
onChanged: (val) {
setState(() {
_scrollBadges = val;
});
2020-05-29 21:16:59 +03:00
_saveBadgesSettings();
},
),
Container(height: Sizes.doubleRowPadding),
2020-05-29 21:20:25 +03:00
Text("Display mode:", style: Theme.of(context).textTheme.body2),
2020-05-29 21:16:59 +03:00
Container(height: Sizes.rowPadding),
DropdownButton<DisplayMode>(
value: _displayMode,
iconSize: 30.0,
isExpanded: true,
style: Theme.of(context).textTheme.title,
items: DisplayMode.values.map((value) {
return new DropdownMenuItem<DisplayMode>(
value: value,
child: Text('${DisplayModeName[value]}'),
);
}).toList(),
onChanged: (DisplayMode val) {
setState(() {
_displayMode = val;
});
_saveDisplayMode(val);
2020-05-09 21:08:42 +03:00
},
),
2020-04-11 19:09:35 +03:00
]
);
}
@override
void dispose() {
super.dispose();
}
}