2021-04-18 09:18:23 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
|
|
|
import 'package:adaptive_theme/adaptive_theme.dart';
|
2021-08-22 06:03:18 +02:00
|
|
|
import 'package:file_picker_cross/file_picker_cross.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';
|
2021-11-13 17:57:55 +01:00
|
|
|
import 'package:fluffychat/config/themes.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 {
|
2021-10-14 18:09:30 +02:00
|
|
|
const SettingsStyle({Key key}) : super(key: key);
|
|
|
|
|
2021-04-18 09:18:23 +02:00
|
|
|
@override
|
|
|
|
SettingsStyleController createState() => SettingsStyleController();
|
|
|
|
}
|
|
|
|
|
|
|
|
class SettingsStyleController extends State<SettingsStyle> {
|
|
|
|
void setWallpaperAction() async {
|
2021-08-10 14:01:15 +02:00
|
|
|
final wallpaper =
|
2021-08-22 06:03:18 +02:00
|
|
|
await FilePickerCross.importFromStorage(type: FileTypeCross.image);
|
2021-04-18 09:18:23 +02:00
|
|
|
if (wallpaper == null) return;
|
|
|
|
Matrix.of(context).wallpaper = File(wallpaper.path);
|
|
|
|
await Matrix.of(context)
|
|
|
|
.store
|
|
|
|
.setItem(SettingKeys.wallpaper, wallpaper.path);
|
|
|
|
setState(() => null);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteWallpaperAction() async {
|
|
|
|
Matrix.of(context).wallpaper = null;
|
|
|
|
await Matrix.of(context).store.deleteItem(SettingKeys.wallpaper);
|
|
|
|
setState(() => null);
|
|
|
|
}
|
|
|
|
|
2021-11-13 17:57:55 +01:00
|
|
|
void setChatColor(Color color) async {
|
|
|
|
await Matrix.of(context).store.setItem(
|
|
|
|
SettingKeys.chatColor,
|
|
|
|
color.value.toString(),
|
|
|
|
);
|
|
|
|
AppConfig.chatColor = color;
|
|
|
|
AdaptiveTheme.of(context).setTheme(
|
|
|
|
light: FluffyThemes.light,
|
|
|
|
dark: FluffyThemes.dark,
|
|
|
|
isDefault: true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-18 09:18:23 +02:00
|
|
|
AdaptiveThemeMode currentTheme;
|
|
|
|
|
2021-11-13 17:57:55 +01:00
|
|
|
static List<Color> customColors = [
|
|
|
|
AppConfig.primaryColor,
|
|
|
|
Colors.blue.shade700,
|
|
|
|
Colors.green.shade700,
|
|
|
|
Colors.pink.shade700,
|
2021-11-13 19:28:33 +01:00
|
|
|
Colors.orange.shade800,
|
2021-11-13 17:57:55 +01:00
|
|
|
];
|
|
|
|
|
2021-04-18 09:18:23 +02:00
|
|
|
void switchTheme(AdaptiveThemeMode newTheme) {
|
|
|
|
switch (newTheme) {
|
|
|
|
case AdaptiveThemeMode.light:
|
|
|
|
AdaptiveTheme.of(context).setLight();
|
|
|
|
break;
|
|
|
|
case AdaptiveThemeMode.dark:
|
|
|
|
AdaptiveTheme.of(context).setDark();
|
|
|
|
break;
|
|
|
|
case AdaptiveThemeMode.system:
|
|
|
|
AdaptiveTheme.of(context).setSystem();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
setState(() => currentTheme = newTheme);
|
|
|
|
}
|
|
|
|
|
|
|
|
void changeFontSizeFactor(double d) {
|
|
|
|
setState(() => AppConfig.fontSizeFactor = d);
|
|
|
|
Matrix.of(context).store.setItem(
|
|
|
|
SettingKeys.fontSizeFactor,
|
|
|
|
AppConfig.fontSizeFactor.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2021-05-22 09:13:47 +02:00
|
|
|
Widget build(BuildContext context) => SettingsStyleView(this);
|
2021-04-18 09:18:23 +02:00
|
|
|
}
|