mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Start to update general settings
This commit is contained in:
		@@ -1,4 +1,5 @@
 | 
			
		||||
import 'package:comunic/ui/routes/account_settings/account_image_settings.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/account_settings/general_account_settings.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:settings_ui/settings_ui.dart';
 | 
			
		||||
@@ -32,6 +33,14 @@ class __AccountSettingsBodyState extends State<_AccountSettingsBody> {
 | 
			
		||||
        SettingsSection(
 | 
			
		||||
          title: tr("Account settings"),
 | 
			
		||||
          tiles: [
 | 
			
		||||
 | 
			
		||||
            SettingsTile(
 | 
			
		||||
              title: tr("General settings"),
 | 
			
		||||
              subtitle: tr("Configure the main settings of your account"),
 | 
			
		||||
              leading: Icon(Icons.settings),
 | 
			
		||||
              onTap: () => _openSection(GeneralAccountSettingsScreen()),
 | 
			
		||||
            ),
 | 
			
		||||
 | 
			
		||||
            SettingsTile(
 | 
			
		||||
              title: tr("Account image"),
 | 
			
		||||
              subtitle: tr("Customize your account image"),
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										103
									
								
								lib/ui/routes/account_settings/general_account_settings.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								lib/ui/routes/account_settings/general_account_settings.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,103 @@
 | 
			
		||||
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();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user