1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-30 08:46:27 +00:00
comunicmobile/lib/ui/routes/settings/account_settings_route.dart

174 lines
5.0 KiB
Dart
Raw Normal View History

2020-05-12 16:42:33 +00:00
import 'package:comunic/ui/routes/settings/account_image_settings.dart';
import 'package:comunic/ui/routes/settings/account_privacy_settings.dart';
import 'package:comunic/ui/routes/settings/account_security_settings.dart';
import 'package:comunic/ui/routes/settings/application_settings.dart';
import 'package:comunic/ui/routes/settings/custom_emojies_account_settings.dart';
import 'package:comunic/ui/routes/settings/general_account_settings.dart';
2020-04-16 14:33:44 +00:00
import 'package:comunic/utils/intl_utils.dart';
2020-05-13 16:12:45 +00:00
import 'package:comunic/utils/ui_utils.dart';
2020-04-16 14:33:44 +00:00
import 'package:flutter/material.dart';
import 'package:settings_ui/settings_ui.dart';
/// Account settings route
///
/// @author Pierre HUBERT
2020-05-13 16:12:45 +00:00
class _SettingsSection {
final String title;
final String subtitle;
final IconData icon;
final Widget Function() onBuild;
const _SettingsSection({
@required this.title,
@required this.subtitle,
@required this.icon,
@required this.onBuild,
}) : assert(title != null),
assert(subtitle != null),
assert(icon != null),
assert(onBuild != null);
}
2020-04-16 14:33:44 +00:00
class AccountSettingsRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2020-05-12 16:42:33 +00:00
title: Text(tr("Settings")),
2020-04-16 14:33:44 +00:00
),
body: _AccountSettingsBody(),
);
}
}
class _AccountSettingsBody extends StatefulWidget {
@override
__AccountSettingsBodyState createState() => __AccountSettingsBodyState();
}
class __AccountSettingsBodyState extends State<_AccountSettingsBody> {
2020-05-13 16:12:45 +00:00
_SettingsSection _currentSection;
2020-04-16 14:33:44 +00:00
@override
2020-05-13 16:12:45 +00:00
void initState() {
super.initState();
2020-04-27 11:27:37 +00:00
2020-05-13 16:12:45 +00:00
/// Choose first section by default
_currentSection = _sections[0];
}
2020-04-28 17:03:23 +00:00
2020-05-13 16:12:45 +00:00
/// The list of settings sections
List<_SettingsSection> get _sections => [
_SettingsSection(
title: tr("General settings"),
subtitle: tr("Configure the main settings of your account"),
icon: Icons.settings,
onBuild: () => GeneralAccountSettingsScreen(),
),
2020-04-29 15:28:47 +00:00
2020-05-13 16:12:45 +00:00
// Emoticons
_SettingsSection(
title: tr("Custom emojis"),
subtitle: tr("Set your own emoticon shorcuts"),
icon: Icons.insert_emoticon,
onBuild: () => CustomEmojisAccountSettings(),
),
2020-05-01 08:52:53 +00:00
2020-05-13 16:12:45 +00:00
// Account image
_SettingsSection(
title: tr("Account image"),
subtitle: tr("Customize your account image"),
icon: Icons.account_circle,
onBuild: () => AccountImageSettingsScreen(),
),
// Security settings
_SettingsSection(
title: tr("Security"),
subtitle: tr("Manage security options of your account"),
icon: Icons.lock,
onBuild: () => AccountSecuritySettingsScreen(),
),
2020-05-12 15:50:05 +00:00
2020-05-13 16:12:45 +00:00
// Privacy settings
_SettingsSection(
title: tr("Privacy"),
subtitle: tr("Here you can make actions to protect your privacy"),
icon: Icons.security,
onBuild: () => AccountPrivacySettings(),
),
// Privacy settings
_SettingsSection(
title: tr("Application settings"),
subtitle: tr("Manage local application settings"),
icon: Icons.smartphone,
onBuild: () => ApplicationSettings(),
),
];
@override
Widget build(BuildContext context) =>
isTablet(context) ? _buildTabletMode() : _buildMobileMode();
/// Tablet mode
Widget _buildTabletMode() => Row(
children: <Widget>[
Container(width: 400, child: _buildTabletLeftPane()),
Expanded(child: _currentSection.onBuild())
],
);
Widget _buildTabletLeftPane() => ListView.builder(
itemBuilder: (c, i) {
final section = _sections[i];
return Container(
color: section.title == _currentSection.title
? Colors.black.withAlpha(50)
: null,
child: ListTile(
title: Text(section.title),
subtitle: Text(section.subtitle),
leading: Icon(section.icon),
onTap: () => _openSectionTablet(section),
2020-05-12 15:50:05 +00:00
),
2020-05-13 16:12:45 +00:00
);
},
itemCount: _sections.length,
);
void _openSectionTablet(_SettingsSection s) =>
setState(() => _currentSection = s);
2020-04-16 14:33:44 +00:00
2020-05-13 16:12:45 +00:00
/// Mobile mode
Widget _buildMobileMode() => SettingsList(
sections: [
SettingsSection(
title: tr("Settings"),
tiles: _sections
.map((f) => SettingsTile(
title: f.title,
leading: Icon(f.icon),
subtitle: f.subtitle,
onTap: () => _openSectionsAsNewRoute(f),
))
.toList(),
)
],
);
/// Push a new route with the settings section
_openSectionsAsNewRoute(_SettingsSection f) {
Navigator.of(context).push(MaterialPageRoute(
builder: (c) => Scaffold(
appBar: AppBar(
title: Text(f.title),
),
body: f.onBuild(),
),
));
2020-04-16 14:33:44 +00:00
}
}