2021-04-18 09:18:23 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
2023-03-18 17:02:12 +01:00
|
|
|
import 'package:collection/collection.dart';
|
|
|
|
import 'package:file_picker/file_picker.dart';
|
2021-04-18 09:18:23 +02:00
|
|
|
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
|
|
import 'package:fluffychat/config/setting_keys.dart';
|
2022-12-24 11:48:48 +01:00
|
|
|
import 'package:fluffychat/widgets/theme_builder.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import '../../widgets/matrix.dart';
|
|
|
|
import 'settings_style_view.dart';
|
2021-04-18 09:18:23 +02:00
|
|
|
|
|
|
|
class SettingsStyle extends StatefulWidget {
|
2022-01-01 13:43:51 +01:00
|
|
|
const SettingsStyle({Key? key}) : super(key: key);
|
2021-10-14 18:09:30 +02:00
|
|
|
|
2021-04-18 09:18:23 +02:00
|
|
|
@override
|
|
|
|
SettingsStyleController createState() => SettingsStyleController();
|
|
|
|
}
|
|
|
|
|
|
|
|
class SettingsStyleController extends State<SettingsStyle> {
|
|
|
|
void setWallpaperAction() async {
|
2023-03-18 17:02:12 +01:00
|
|
|
final picked = await FilePicker.platform.pickFiles(
|
|
|
|
type: FileType.image,
|
|
|
|
withData: false,
|
|
|
|
);
|
|
|
|
final pickedFile = picked?.files.firstOrNull;
|
|
|
|
|
|
|
|
if (pickedFile == null) return;
|
2021-04-18 09:18:23 +02:00
|
|
|
await Matrix.of(context)
|
|
|
|
.store
|
2023-03-18 17:02:12 +01:00
|
|
|
.setItem(SettingKeys.wallpaper, pickedFile.path);
|
2022-01-01 13:43:51 +01:00
|
|
|
setState(() {});
|
2021-04-18 09:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void deleteWallpaperAction() async {
|
|
|
|
Matrix.of(context).wallpaper = null;
|
|
|
|
await Matrix.of(context).store.deleteItem(SettingKeys.wallpaper);
|
2022-01-01 13:43:51 +01:00
|
|
|
setState(() {});
|
2021-04-18 09:18:23 +02:00
|
|
|
}
|
|
|
|
|
2022-05-18 08:54:50 +02:00
|
|
|
void setChatColor(Color? color) async {
|
|
|
|
AppConfig.colorSchemeSeed = color;
|
2022-12-24 11:48:48 +01:00
|
|
|
ThemeController.of(context).setPrimaryColor(color);
|
2021-11-13 17:57:55 +01:00
|
|
|
}
|
|
|
|
|
2022-12-24 11:48:48 +01:00
|
|
|
ThemeMode get currentTheme => ThemeController.of(context).themeMode;
|
|
|
|
Color? get currentColor => ThemeController.of(context).primaryColor;
|
2021-04-18 09:18:23 +02:00
|
|
|
|
2022-05-18 08:54:50 +02:00
|
|
|
static final List<Color?> customColors = [
|
2022-12-24 11:48:48 +01:00
|
|
|
AppConfig.chatColor,
|
2023-03-19 19:59:50 +01:00
|
|
|
Colors.indigo,
|
|
|
|
Colors.green,
|
|
|
|
Colors.orange,
|
|
|
|
Colors.pink,
|
|
|
|
Colors.blueGrey,
|
2022-05-18 08:54:50 +02:00
|
|
|
null,
|
2021-11-15 07:59:51 +01:00
|
|
|
];
|
2021-11-13 17:57:55 +01:00
|
|
|
|
2022-12-24 11:48:48 +01:00
|
|
|
void switchTheme(ThemeMode? newTheme) {
|
2022-01-01 13:43:51 +01:00
|
|
|
if (newTheme == null) return;
|
2021-04-18 09:18:23 +02:00
|
|
|
switch (newTheme) {
|
2022-12-24 11:48:48 +01:00
|
|
|
case ThemeMode.light:
|
|
|
|
ThemeController.of(context).setThemeMode(ThemeMode.light);
|
2021-04-18 09:18:23 +02:00
|
|
|
break;
|
2022-12-24 11:48:48 +01:00
|
|
|
case ThemeMode.dark:
|
|
|
|
ThemeController.of(context).setThemeMode(ThemeMode.dark);
|
2021-04-18 09:18:23 +02:00
|
|
|
break;
|
2022-12-24 11:48:48 +01:00
|
|
|
case ThemeMode.system:
|
|
|
|
ThemeController.of(context).setThemeMode(ThemeMode.system);
|
2021-04-18 09:18:23 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-12-24 11:48:48 +01:00
|
|
|
setState(() {});
|
2021-04-18 09:18:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void changeFontSizeFactor(double d) {
|
|
|
|
setState(() => AppConfig.fontSizeFactor = d);
|
|
|
|
Matrix.of(context).store.setItem(
|
|
|
|
SettingKeys.fontSizeFactor,
|
|
|
|
AppConfig.fontSizeFactor.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-03 23:19:51 +01:00
|
|
|
void changeBubbleSizeFactor(double d) {
|
|
|
|
setState(() => AppConfig.bubbleSizeFactor = d);
|
|
|
|
Matrix.of(context).store.setItem(
|
|
|
|
SettingKeys.bubbleSizeFactor,
|
|
|
|
AppConfig.bubbleSizeFactor.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-18 09:18:23 +02:00
|
|
|
@override
|
2021-05-22 09:13:47 +02:00
|
|
|
Widget build(BuildContext context) => SettingsStyleView(this);
|
2021-04-18 09:18:23 +02:00
|
|
|
}
|