mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-02-23 00:41:14 +00:00
104 lines
2.7 KiB
Dart
104 lines
2.7 KiB
Dart
|
import 'package:comunic/helpers/settings_helper.dart';
|
||
|
import 'package:comunic/models/general_settings.dart';
|
||
|
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
||
|
import 'package:comunic/ui/widgets/settings/text_settings_edit_tile.dart';
|
||
|
import 'package:comunic/utils/account_utils.dart';
|
||
|
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';
|
||
|
|
||
|
/// General account settings
|
||
|
///
|
||
|
/// @author Pierre HUBERT
|
||
|
|
||
|
class GeneralAccountSettingsScreen extends StatelessWidget {
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
title: Text("General settings"),
|
||
|
),
|
||
|
body: _GeneralAccountSettingsBody(),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class _GeneralAccountSettingsBody extends StatefulWidget {
|
||
|
@override
|
||
|
__GeneralAccountSettingsBodyState createState() =>
|
||
|
__GeneralAccountSettingsBodyState();
|
||
|
}
|
||
|
|
||
|
class __GeneralAccountSettingsBodyState
|
||
|
extends State<_GeneralAccountSettingsBody> {
|
||
|
GeneralSettings _settings;
|
||
|
|
||
|
final _key = GlobalKey<AsyncScreenWidgetState>();
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return AsyncScreenWidget(
|
||
|
key: _key,
|
||
|
onReload: () async =>
|
||
|
_settings = await SettingsHelper.getGeneralSettings(),
|
||
|
onBuild: _buildSettings,
|
||
|
errorMessage: tr("Could not load general settings!"));
|
||
|
}
|
||
|
|
||
|
Widget _buildSettings() {
|
||
|
return SettingsList(
|
||
|
sections: [
|
||
|
SettingsSection(
|
||
|
title: tr("Main account information"),
|
||
|
tiles: _mainInformationTiles(),
|
||
|
)
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
|
||
|
List<SettingsTile> _mainInformationTiles() {
|
||
|
return [
|
||
|
SettingsTile(
|
||
|
title: tr("User ID"),
|
||
|
subtitle: "${userID()}",
|
||
|
),
|
||
|
SettingsTile(
|
||
|
title: tr("Email address"),
|
||
|
subtitle: _settings.email,
|
||
|
),
|
||
|
|
||
|
// First name
|
||
|
TextEditSettingsTile(
|
||
|
title: tr("First name"),
|
||
|
currValue: _settings.firstName,
|
||
|
onChanged: (s) {
|
||
|
_settings.firstName = s;
|
||
|
_updateSettings();
|
||
|
},
|
||
|
),
|
||
|
|
||
|
// Last name
|
||
|
TextEditSettingsTile(
|
||
|
title: tr("Last name"),
|
||
|
currValue: _settings.lastName,
|
||
|
onChanged: (s) {
|
||
|
_settings.lastName = s;
|
||
|
_updateSettings();
|
||
|
},
|
||
|
),
|
||
|
];
|
||
|
}
|
||
|
|
||
|
/// Apply new settings
|
||
|
Future<void> _updateSettings() async {
|
||
|
try {
|
||
|
await SettingsHelper.updateGeneralSettings(_settings);
|
||
|
} catch (e, stack) {
|
||
|
print("Error while updating settings! $e/n$stack");
|
||
|
showSimpleSnack(context, tr("Could not update general settings!"));
|
||
|
}
|
||
|
_key.currentState.refresh();
|
||
|
}
|
||
|
}
|