1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 14:29:22 +00:00
comunicmobile/lib/ui/routes/settings/application_settings.dart

122 lines
3.4 KiB
Dart
Raw Normal View History

2020-05-12 15:50:05 +00:00
import 'package:comunic/helpers/preferences_helper.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
2021-02-12 21:36:22 +00:00
import 'package:comunic/ui/widgets/settings/header_spacer_section.dart';
2021-04-27 07:44:11 +00:00
import 'package:comunic/utils/flutter_utils.dart';
2020-05-12 15:50:05 +00:00
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
import 'package:settings_ui/settings_ui.dart';
/// Application settings
///
/// @author Pierre Hubert
2020-05-13 16:12:45 +00:00
class ApplicationSettings extends StatefulWidget {
2020-05-12 15:50:05 +00:00
@override
2020-05-13 16:21:30 +00:00
_ApplicationSettingsState createState() => _ApplicationSettingsState();
2020-05-12 15:50:05 +00:00
}
2020-05-13 16:21:30 +00:00
class _ApplicationSettingsState extends State<ApplicationSettings> {
2020-05-12 15:50:05 +00:00
PreferencesHelper _preferencesHelper;
Future<void> _refresh() async {
_preferencesHelper = await PreferencesHelper.getInstance();
}
@override
Widget build(BuildContext context) => AsyncScreenWidget(
onReload: _refresh,
onBuild: _buildSections,
errorMessage: tr("Could not load settings!"));
Widget _buildSections() {
return SettingsList(
2020-05-13 16:21:30 +00:00
sections: [
2021-02-12 21:36:22 +00:00
HeadSpacerSection(),
2020-05-13 16:21:30 +00:00
_buildAppearanceSection(),
_buildDebugSection()
],
2020-05-12 15:50:05 +00:00
);
}
/// Appearance section
SettingsSection _buildAppearanceSection() => SettingsSection(
title: tr("Appearance"),
tiles: [
_PreferencesSettingsTile(
preferencesKey: PreferencesKeyList.ENABLE_DARK_THEME,
title: tr("Enable dark theme"),
subtitle: null,
onChange: _updatedSettings,
helper: _preferencesHelper,
),
],
);
2020-05-13 16:21:30 +00:00
/// Debug section
SettingsSection _buildDebugSection() => SettingsSection(
title: tr("Debug features"),
tiles: [
2020-05-13 16:26:21 +00:00
// Force mobile mode
2020-05-13 16:21:30 +00:00
_PreferencesSettingsTile(
preferencesKey: PreferencesKeyList.FORCE_MOBILE_MODE,
title: tr("Force mobile mode"),
2021-04-27 07:44:11 +00:00
subtitle: isIOS
? null
: tr(
"Force the smartphone mode of the application to be used, even when tablet mode could be used."),
2020-05-13 16:21:30 +00:00
onChange: _updatedSettings,
helper: _preferencesHelper,
),
2020-05-13 16:26:21 +00:00
// Show performances overlay
_PreferencesSettingsTile(
preferencesKey: PreferencesKeyList.SHOW_PERFORMANCE_OVERLAY,
title: tr("Show performances overlay"),
subtitle: null,
onChange: _updatedSettings,
helper: _preferencesHelper,
),
2020-05-13 16:21:30 +00:00
],
);
2020-05-12 15:50:05 +00:00
/// Apply new settings
_updatedSettings() {
setState(() {});
applyNewThemeSettings(context);
2020-05-12 15:50:05 +00:00
}
}
class _PreferencesSettingsTile extends SettingsTile {
final PreferencesKeyList preferencesKey;
final String title;
final String subtitle;
final Function onChange;
final PreferencesHelper helper;
const _PreferencesSettingsTile({
@required this.preferencesKey,
@required this.title,
@required this.subtitle,
@required this.onChange,
@required this.helper,
});
@override
Widget build(BuildContext context) {
return SettingsTile.switchTile(
title: title,
subtitle: subtitle,
onToggle: _doChange,
switchValue: helper.getBool(preferencesKey),
2021-04-17 06:40:33 +00:00
titleMaxLines: 2,
2021-04-27 07:44:11 +00:00
subtitleMaxLines: 4,
2020-05-12 15:50:05 +00:00
);
}
void _doChange(bool value) async {
await helper.setBool(preferencesKey, value);
onChange();
}
}