fluffychat/lib/pages/settings/settings_view.dart

208 lines
8.6 KiB
Dart
Raw Normal View History

2020-01-01 18:10:13 +00:00
import 'package:flutter/material.dart';
2021-10-26 16:50:34 +00:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';
2023-02-04 17:32:56 +00:00
import 'package:matrix/matrix.dart';
2023-01-26 08:47:30 +00:00
import 'package:url_launcher/url_launcher_string.dart';
2020-01-01 18:10:13 +00:00
2021-10-26 16:50:34 +00:00
import 'package:fluffychat/config/app_config.dart';
2023-02-05 06:39:03 +00:00
import 'package:fluffychat/utils/fluffy_share.dart';
2021-10-26 16:50:34 +00:00
import 'package:fluffychat/utils/platform_infos.dart';
2023-02-04 17:32:56 +00:00
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';
2021-11-09 20:32:16 +00:00
import 'settings.dart';
2020-01-01 18:10:13 +00:00
2021-05-22 07:13:47 +00:00
class SettingsView extends StatelessWidget {
2021-04-24 06:22:42 +00:00
final SettingsController controller;
2020-06-25 14:29:06 +00:00
2022-01-29 11:35:03 +00:00
const SettingsView(this.controller, {Key? key}) : super(key: key);
2021-01-18 07:38:19 +00:00
2020-01-01 18:10:13 +00:00
@override
Widget build(BuildContext context) {
2023-02-07 12:52:14 +00:00
final showChatBackupBanner = controller.showChatBackupBanner;
2021-02-13 10:55:22 +00:00
return Scaffold(
2023-02-04 17:32:56 +00:00
appBar: AppBar(
2023-02-04 20:59:53 +00:00
leading: CloseButton(
2023-08-07 16:40:02 +00:00
onPressed: () => context.go('/rooms'),
2023-02-04 20:59:53 +00:00
),
2023-02-04 17:32:56 +00:00
title: Text(L10n.of(context)!.settings),
actions: [
TextButton.icon(
onPressed: controller.logoutAction,
label: Text(L10n.of(context)!.logout),
icon: const Icon(Icons.logout_outlined),
2020-01-01 18:10:13 +00:00
),
2021-02-13 10:55:22 +00:00
],
2023-02-04 17:32:56 +00:00
),
body: ListTileTheme(
iconColor: Theme.of(context).colorScheme.onBackground,
child: ListView(
key: const Key('SettingsListViewContent'),
children: <Widget>[
FutureBuilder<Profile>(
future: controller.profileFuture,
builder: (context, snapshot) {
final profile = snapshot.data;
final mxid =
Matrix.of(context).client.userID ?? L10n.of(context)!.user;
final displayname =
profile?.displayName ?? mxid.localpart ?? mxid;
return Row(
children: [
Padding(
padding: const EdgeInsets.all(32.0),
child: Stack(
children: [
Material(
elevation: Theme.of(context)
.appBarTheme
.scrolledUnderElevation ??
4,
shadowColor:
Theme.of(context).appBarTheme.shadowColor,
shape: RoundedRectangleBorder(
side: BorderSide(
color: Theme.of(context).dividerColor,
2023-02-04 17:32:56 +00:00
),
borderRadius: BorderRadius.circular(
Avatar.defaultSize * 2.5,
2023-02-04 17:32:56 +00:00
),
),
child: Avatar(
mxContent: profile?.avatarUrl,
name: displayname,
size: Avatar.defaultSize * 2.5,
fontSize: 18 * 2.5,
),
),
if (profile != null)
Positioned(
bottom: 0,
right: 0,
child: FloatingActionButton.small(
onPressed: controller.setAvatarAction,
heroTag: null,
child: const Icon(Icons.camera_alt_outlined),
2023-02-04 17:32:56 +00:00
),
),
],
2023-02-04 17:32:56 +00:00
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextButton.icon(
onPressed: controller.setDisplaynameAction,
icon: const Icon(
Icons.edit_outlined,
size: 16,
2023-02-04 17:32:56 +00:00
),
style: TextButton.styleFrom(
foregroundColor:
Theme.of(context).colorScheme.onBackground,
),
label: Text(
displayname,
maxLines: 1,
overflow: TextOverflow.ellipsis,
// style: const TextStyle(fontSize: 18),
),
),
TextButton.icon(
onPressed: () => FluffyShare.share(mxid, context),
icon: const Icon(
Icons.copy_outlined,
size: 14,
),
style: TextButton.styleFrom(
foregroundColor:
Theme.of(context).colorScheme.secondary,
),
label: Text(
mxid,
maxLines: 1,
overflow: TextOverflow.ellipsis,
// style: const TextStyle(fontSize: 12),
2023-02-04 17:32:56 +00:00
),
),
],
2023-02-04 17:32:56 +00:00
),
),
],
);
},
),
2023-02-04 17:32:56 +00:00
const Divider(thickness: 1),
2023-02-07 12:52:14 +00:00
if (showChatBackupBanner == null)
ListTile(
leading: const Icon(Icons.backup_outlined),
title: Text(L10n.of(context)!.chatBackup),
trailing: const CircularProgressIndicator.adaptive(),
)
else
SwitchListTile.adaptive(
controlAffinity: ListTileControlAffinity.trailing,
value: controller.showChatBackupBanner == false,
secondary: const Icon(Icons.backup_outlined),
title: Text(L10n.of(context)!.chatBackup),
onChanged: controller.firstRunBootstrapAction,
),
2023-02-04 17:32:56 +00:00
const Divider(thickness: 1),
ListTile(
leading: const Icon(Icons.format_paint_outlined),
title: Text(L10n.of(context)!.changeTheme),
2023-08-07 16:40:02 +00:00
onTap: () => context.go('/rooms/settings/style'),
2023-02-04 17:32:56 +00:00
trailing: const Icon(Icons.chevron_right_outlined),
),
ListTile(
leading: const Icon(Icons.notifications_outlined),
title: Text(L10n.of(context)!.notifications),
2023-08-07 16:40:02 +00:00
onTap: () => context.go('/rooms/settings/notifications'),
2023-02-04 17:32:56 +00:00
trailing: const Icon(Icons.chevron_right_outlined),
),
ListTile(
leading: const Icon(Icons.devices_outlined),
title: Text(L10n.of(context)!.devices),
2023-08-07 16:40:02 +00:00
onTap: () => context.go('/rooms/settings/devices'),
2023-02-04 17:32:56 +00:00
trailing: const Icon(Icons.chevron_right_outlined),
),
ListTile(
leading: const Icon(Icons.forum_outlined),
2023-02-04 17:32:56 +00:00
title: Text(L10n.of(context)!.chat),
2023-08-07 16:40:02 +00:00
onTap: () => context.go('/rooms/settings/chat'),
2023-02-04 17:32:56 +00:00
trailing: const Icon(Icons.chevron_right_outlined),
),
ListTile(
leading: const Icon(Icons.shield_outlined),
title: Text(L10n.of(context)!.security),
2023-08-07 16:40:02 +00:00
onTap: () => context.go('/rooms/settings/security'),
2023-02-04 17:32:56 +00:00
trailing: const Icon(Icons.chevron_right_outlined),
),
const Divider(thickness: 1),
ListTile(
leading: const Icon(Icons.help_outline_outlined),
title: Text(L10n.of(context)!.help),
onTap: () => launchUrlString(AppConfig.supportUrl),
trailing: const Icon(Icons.open_in_new_outlined),
),
ListTile(
leading: const Icon(Icons.shield_sharp),
title: Text(L10n.of(context)!.privacy),
onTap: () => launchUrlString(AppConfig.privacyUrl),
trailing: const Icon(Icons.open_in_new_outlined),
),
ListTile(
leading: const Icon(Icons.info_outline_rounded),
title: Text(L10n.of(context)!.about),
onTap: () => PlatformInfos.showDialog(context),
trailing: const Icon(Icons.chevron_right_outlined),
),
],
2021-02-03 14:47:51 +00:00
),
2021-02-13 10:55:22 +00:00
),
2020-01-01 18:10:13 +00:00
);
}
}