mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Create application settings section
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
import 'package:comunic/ui/routes/account_settings/account_image_settings.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/account_settings/account_privacy_settings.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/account_settings/account_security_settings.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/account_settings/application_settings.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/account_settings/custom_emojies_account_settings.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/account_settings/general_account_settings.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
@@ -75,6 +76,14 @@ class __AccountSettingsBodyState extends State<_AccountSettingsBody> {
 | 
			
		||||
              leading: Icon(Icons.security),
 | 
			
		||||
              onTap: () => _openSection(AccountPrivacySettings()),
 | 
			
		||||
            ),
 | 
			
		||||
 | 
			
		||||
            // Privacy settings
 | 
			
		||||
            SettingsTile(
 | 
			
		||||
              title: tr("Application settings"),
 | 
			
		||||
              subtitle: tr("Manage local application settings"),
 | 
			
		||||
              leading: Icon(Icons.smartphone),
 | 
			
		||||
              onTap: () => _openSection(ApplicationSettings()),
 | 
			
		||||
            ),
 | 
			
		||||
          ],
 | 
			
		||||
        )
 | 
			
		||||
      ],
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										109
									
								
								lib/ui/routes/account_settings/application_settings.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								lib/ui/routes/account_settings/application_settings.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,109 @@
 | 
			
		||||
import 'package:comunic/helpers/preferences_helper.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/async_screen_widget.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';
 | 
			
		||||
 | 
			
		||||
/// Application settings
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
 | 
			
		||||
class ApplicationSettings extends StatelessWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
      appBar: AppBar(title: Text(tr("Application settings"))),
 | 
			
		||||
      body: _ApplicationSettingsScreen(),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _ApplicationSettingsScreen extends StatefulWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  __ApplicationSettingsScreenState createState() =>
 | 
			
		||||
      __ApplicationSettingsScreenState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class __ApplicationSettingsScreenState
 | 
			
		||||
    extends State<_ApplicationSettingsScreen> {
 | 
			
		||||
  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(
 | 
			
		||||
      sections: [_buildAppearanceSection(), _buildGeneralSection()],
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// 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,
 | 
			
		||||
          ),
 | 
			
		||||
        ],
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  /// General section
 | 
			
		||||
  SettingsSection _buildGeneralSection() => SettingsSection(
 | 
			
		||||
        title: tr("General"),
 | 
			
		||||
        tiles: [
 | 
			
		||||
          SettingsTile(
 | 
			
		||||
            title: tr("About this application"),
 | 
			
		||||
            subtitle: tr("Learn more about us"),
 | 
			
		||||
            onTap: () => showAboutAppDialog(context),
 | 
			
		||||
          )
 | 
			
		||||
        ],
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  /// Apply new settings
 | 
			
		||||
  _updatedSettings() {
 | 
			
		||||
    setState(() {});
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void _doChange(bool value) async {
 | 
			
		||||
    await helper.setBool(preferencesKey, value);
 | 
			
		||||
    onChange();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user