mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-01-30 21:53:00 +00:00
68 lines
2.0 KiB
Dart
68 lines
2.0 KiB
Dart
|
import 'package:comunic/helpers/settings_helper.dart';
|
||
|
import 'package:comunic/models/notifications_settings.dart';
|
||
|
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
||
|
import 'package:comunic/ui/widgets/settings/header_spacer_section.dart';
|
||
|
import 'package:comunic/utils/intl_utils.dart';
|
||
|
import 'package:comunic/utils/log_utils.dart';
|
||
|
import 'package:comunic/utils/ui_utils.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:settings_ui/settings_ui.dart';
|
||
|
|
||
|
/// Notifications settings
|
||
|
///
|
||
|
/// @author Pierre Hubert
|
||
|
|
||
|
class NotificationsSettingsScreen extends StatefulWidget {
|
||
|
@override
|
||
|
_NotificationsSettingsScreenState createState() =>
|
||
|
_NotificationsSettingsScreenState();
|
||
|
}
|
||
|
|
||
|
class _NotificationsSettingsScreenState
|
||
|
extends State<NotificationsSettingsScreen> {
|
||
|
final key = GlobalKey<AsyncScreenWidgetState>();
|
||
|
|
||
|
NotificationsSettings _settings;
|
||
|
|
||
|
Future<void> _loadSettings() async {
|
||
|
_settings = await SettingsHelper.getNotificationsSettings();
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) => AsyncScreenWidget(
|
||
|
key: key,
|
||
|
onReload: _loadSettings,
|
||
|
onBuild: _buildScreen,
|
||
|
errorMessage: tr("Failed to load notifications settings!"),
|
||
|
);
|
||
|
|
||
|
Widget _buildScreen() => SettingsList(sections: [
|
||
|
HeadSpacerSection(),
|
||
|
SettingsSection(
|
||
|
title: tr("Push notifications"),
|
||
|
tiles: [
|
||
|
SettingsTile.switchTile(
|
||
|
title: tr("Allow conversations notification"),
|
||
|
onToggle: (v) {
|
||
|
_settings.allowConversations = v;
|
||
|
_updatedSettings();
|
||
|
},
|
||
|
switchValue: _settings.allowConversations,
|
||
|
subtitle:
|
||
|
tr("Receive notifications for the conversations you follow."),
|
||
|
)
|
||
|
],
|
||
|
)
|
||
|
]);
|
||
|
|
||
|
void _updatedSettings() async {
|
||
|
try {
|
||
|
await SettingsHelper.setNotificationsSettings(_settings);
|
||
|
setState(() {});
|
||
|
} catch (e, s) {
|
||
|
logError(e, s);
|
||
|
snack(context, tr("Failed to update settings!"));
|
||
|
}
|
||
|
}
|
||
|
}
|