fluffychat/lib/pages/settings_style/settings_style_view.dart

291 lines
13 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2021-10-26 16:50:34 +00:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
2023-08-11 11:55:38 +00:00
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/utils/account_config.dart';
import 'package:fluffychat/widgets/avatar.dart';
2021-10-26 16:50:34 +00:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/mxc_image.dart';
import '../../config/app_config.dart';
2021-11-09 20:32:16 +00:00
import 'settings_style.dart';
2021-05-22 07:13:47 +00:00
class SettingsStyleView extends StatelessWidget {
2021-04-18 07:18:23 +00:00
final SettingsStyleController controller;
const SettingsStyleView(this.controller, {super.key});
2021-01-15 18:41:55 +00:00
@override
Widget build(BuildContext context) {
const colorPickerSize = 32.0;
final client = Matrix.of(context).client;
return Scaffold(
appBar: AppBar(
leading: const Center(child: BackButton()),
title: Text(L10n.of(context)!.changeTheme),
),
2022-05-18 06:54:50 +00:00
backgroundColor: Theme.of(context).colorScheme.surface,
2021-04-09 16:26:44 +00:00
body: MaxWidthBody(
child: Column(
children: [
2023-08-11 11:55:38 +00:00
ListTile(
title: Text(
L10n.of(context)!.setColorTheme,
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
),
2022-05-18 06:54:50 +00:00
SizedBox(
height: colorPickerSize + 24,
child: ListView(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
children: SettingsStyleController.customColors
.map(
(color) => Padding(
padding: const EdgeInsets.all(12.0),
child: InkWell(
borderRadius: BorderRadius.circular(colorPickerSize),
2022-05-18 06:54:50 +00:00
onTap: () => controller.setChatColor(color),
child: color == null
? Material(
2023-08-11 11:55:38 +00:00
elevation: 6,
2022-05-18 06:54:50 +00:00
shadowColor: AppConfig.colorSchemeSeed,
borderRadius:
BorderRadius.circular(colorPickerSize),
2023-08-11 11:55:38 +00:00
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
colorPickerSize,
),
gradient: FluffyThemes.backgroundGradient(
context,
255,
),
),
child: SizedBox(
height: colorPickerSize,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8.0,
),
child: Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (controller.currentColor ==
null)
Padding(
padding:
const EdgeInsets.only(
right: 8.0,
),
child: Icon(
Icons.check,
size: 16,
color: Theme.of(context)
.colorScheme
.onBackground,
),
),
Text(
L10n.of(context)!.systemTheme,
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context)
.colorScheme
.onBackground,
),
),
],
),
),
),
),
2022-05-18 06:54:50 +00:00
),
)
: Material(
color: color,
elevation: 6,
borderRadius:
BorderRadius.circular(colorPickerSize),
child: SizedBox(
width: colorPickerSize,
height: colorPickerSize,
child: controller.currentColor == color
? const Center(
child: Icon(
2022-05-18 06:54:50 +00:00
Icons.check,
size: 16,
color: Colors.white,
),
)
: null,
),
2022-05-18 06:54:50 +00:00
),
),
),
2022-05-18 06:54:50 +00:00
)
.toList(),
),
),
2023-08-11 11:55:38 +00:00
const SizedBox(height: 8),
const Divider(height: 1),
2023-08-11 11:55:38 +00:00
ListTile(
title: Text(
L10n.of(context)!.setTheme,
style: TextStyle(
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
),
2022-12-24 10:48:48 +00:00
RadioListTile<ThemeMode>(
2021-04-18 07:18:23 +00:00
groupValue: controller.currentTheme,
2022-12-24 10:48:48 +00:00
value: ThemeMode.system,
title: Text(L10n.of(context)!.systemTheme),
2021-04-18 07:18:23 +00:00
onChanged: controller.switchTheme,
),
2022-12-24 10:48:48 +00:00
RadioListTile<ThemeMode>(
2021-04-18 07:18:23 +00:00
groupValue: controller.currentTheme,
2022-12-24 10:48:48 +00:00
value: ThemeMode.light,
title: Text(L10n.of(context)!.lightTheme),
2021-04-18 07:18:23 +00:00
onChanged: controller.switchTheme,
),
2022-12-24 10:48:48 +00:00
RadioListTile<ThemeMode>(
2021-04-18 07:18:23 +00:00
groupValue: controller.currentTheme,
2022-12-24 10:48:48 +00:00
value: ThemeMode.dark,
title: Text(L10n.of(context)!.darkTheme),
2021-04-18 07:18:23 +00:00
onChanged: controller.switchTheme,
2021-04-09 16:26:44 +00:00
),
2021-10-14 16:09:30 +00:00
const Divider(height: 1),
2021-04-09 16:26:44 +00:00
ListTile(
title: Text(
2023-08-11 11:55:38 +00:00
L10n.of(context)!.messagesStyle,
2021-02-07 07:59:58 +00:00
style: TextStyle(
2021-05-24 08:59:00 +00:00
color: Theme.of(context).colorScheme.secondary,
2021-04-09 16:26:44 +00:00
fontWeight: FontWeight.bold,
),
),
),
StreamBuilder(
stream: client.onAccountData.stream.where(
(data) =>
data.type ==
ApplicationAccountConfigExtension.accountDataKey,
2021-02-07 07:59:58 +00:00
),
builder: (context, snapshot) {
final accountConfig = client.applicationAccountConfig;
final wallpaperOpacity = accountConfig.wallpaperOpacity ?? 1;
final wallpaperOpacityIsDefault = wallpaperOpacity == 1;
return Column(
mainAxisSize: MainAxisSize.min,
children: [
AnimatedContainer(
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
alignment: Alignment.centerLeft,
decoration: const BoxDecoration(),
clipBehavior: Clip.hardEdge,
child: Stack(
children: [
if (accountConfig.wallpaperUrl != null)
Opacity(
opacity: wallpaperOpacity,
child: MxcImage(
uri: accountConfig.wallpaperUrl,
fit: BoxFit.cover,
isThumbnail: true,
width: FluffyThemes.columnWidth * 2,
height: 156,
),
),
Padding(
padding: EdgeInsets.only(
left: 12 + 12 + Avatar.defaultSize,
right: 12,
top: accountConfig.wallpaperUrl == null ? 0 : 12,
bottom: 12,
),
child: Material(
color: Theme.of(context)
.colorScheme
.primaryContainer,
borderRadius: BorderRadius.circular(
AppConfig.borderRadius,
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
child: Text(
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor',
style: TextStyle(
color: Theme.of(context)
.colorScheme
.onPrimaryContainer,
fontSize: AppConfig.messageFontSize *
AppConfig.fontSizeFactor,
),
),
),
),
),
],
),
),
ListTile(
title: Text(L10n.of(context)!.wallpaper),
leading: const Icon(Icons.photo_outlined),
trailing: accountConfig.wallpaperUrl == null
? null
: IconButton(
icon: const Icon(Icons.delete_outlined),
color: Theme.of(context).colorScheme.error,
onPressed: controller.deleteChatWallpaper,
),
onTap: controller.setWallpaper,
),
AnimatedSize(
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
child: accountConfig.wallpaperUrl != null
? SwitchListTile.adaptive(
title: Text(L10n.of(context)!.transparent),
secondary: const Icon(Icons.blur_linear_outlined),
value: !wallpaperOpacityIsDefault,
onChanged: (_) =>
controller.setChatWallpaperOpacity(
wallpaperOpacityIsDefault ? 0.4 : 1,
),
)
: null,
),
],
);
},
2021-02-07 07:59:58 +00:00
),
ListTile(
title: Text(L10n.of(context)!.fontSize),
trailing: Text('× ${AppConfig.fontSizeFactor}'),
),
Slider.adaptive(
2021-04-09 16:26:44 +00:00
min: 0.5,
max: 2.5,
divisions: 20,
2021-04-09 16:26:44 +00:00
value: AppConfig.fontSizeFactor,
semanticFormatterCallback: (d) => d.toString(),
2021-04-18 07:18:23 +00:00
onChanged: controller.changeFontSizeFactor,
2021-04-09 16:26:44 +00:00
),
],
),
),
);
}
}