mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-09 21:49:31 +01:00
62 lines
1.8 KiB
Dart
62 lines
1.8 KiB
Dart
|
import 'dart:io';
|
||
|
|
||
|
import 'package:adaptive_theme/adaptive_theme.dart';
|
||
|
import 'package:fluffychat/config/app_config.dart';
|
||
|
import 'package:fluffychat/config/setting_keys.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:image_picker/image_picker.dart';
|
||
|
|
||
|
import 'ui/settings_style_ui.dart';
|
||
|
import 'widgets/matrix.dart';
|
||
|
|
||
|
class SettingsStyle extends StatefulWidget {
|
||
|
@override
|
||
|
SettingsStyleController createState() => SettingsStyleController();
|
||
|
}
|
||
|
|
||
|
class SettingsStyleController extends State<SettingsStyle> {
|
||
|
void setWallpaperAction() async {
|
||
|
final wallpaper = await ImagePicker().getImage(source: ImageSource.gallery);
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
AdaptiveThemeMode currentTheme;
|
||
|
|
||
|
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
|
||
|
Widget build(BuildContext context) => SettingsStyleUI(this);
|
||
|
}
|