1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-27 05:18:50 +00:00
comunicmobile/lib/ui/routes/app_settings_route.dart

110 lines
2.7 KiB
Dart
Raw Normal View History

2019-11-01 12:48:40 +00:00
import 'package:comunic/helpers/preferences_helper.dart';
2019-11-01 08:59:22 +00:00
import 'package:comunic/utils/intl_utils.dart';
2020-05-03 15:00:38 +00:00
import 'package:comunic/utils/ui_utils.dart';
2019-11-01 08:59:22 +00:00
import 'package:flutter/material.dart';
/// Application settings route
///
/// @author Pierre HUBERT
class AppSettingsRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(tr("App settings")),
),
body: _AppSettingsBody(),
);
}
}
class _AppSettingsBody extends StatefulWidget {
@override
__AppSettingsBodyState createState() => __AppSettingsBodyState();
}
class __AppSettingsBodyState extends State<_AppSettingsBody> {
2019-11-01 12:48:40 +00:00
PreferencesHelper _preferencesHelper;
@override
void initState() {
super.initState();
_load();
}
void _load() async {
final prefs = await PreferencesHelper.getInstance();
setState(() {
_preferencesHelper = prefs;
});
}
void _needRefresh() {
setState(() {});
}
2019-11-01 08:59:22 +00:00
@override
Widget build(BuildContext context) {
2019-11-01 12:48:40 +00:00
if (_preferencesHelper == null)
return Center(child: CircularProgressIndicator());
return Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: <Widget>[
// Dark theme
_CheckBoxPreference(
preferenceKey: PreferencesKeyList.ENABLE_DARK_THEME,
preferencesHelper: _preferencesHelper,
onUpdate: _needRefresh,
title: tr("Enable dark theme"),
description:
tr("You will need to restart the application to apply changes"),
),
2020-05-03 15:00:38 +00:00
ListTile(
title: Text(tr("About Comunic")),
onTap: () => showAboutAppDialog(context),
),
2019-11-01 12:48:40 +00:00
],
),
);
2019-11-01 08:59:22 +00:00
}
}
2019-11-01 12:48:40 +00:00
class _CheckBoxPreference extends StatelessWidget {
final PreferencesKeyList preferenceKey;
final PreferencesHelper preferencesHelper;
final VoidCallback onUpdate;
final String title;
final String description;
const _CheckBoxPreference({
Key key,
@required this.preferenceKey,
@required this.preferencesHelper,
@required this.onUpdate,
@required this.title,
@required this.description,
}) : assert(preferencesHelper != null),
assert(preferencesHelper != null),
assert(onUpdate != null),
assert(title != null),
assert(description != null),
super(key: key);
@override
Widget build(BuildContext context) {
return SwitchListTile(
value: preferencesHelper.getBool(preferenceKey),
onChanged: (b) async {
await preferencesHelper.setBool(preferenceKey, b);
onUpdate();
return true;
},
title: Text(title),
subtitle: Text(description),
);
}
}