mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-12 18:52:39 +01:00
refactor: MVC settings style
This commit is contained in:
parent
586c2481de
commit
c6083b6491
@ -25,7 +25,7 @@ import 'package:fluffychat/views/ui/settings_emotes_ui.dart';
|
|||||||
import 'package:fluffychat/views/ui/settings_ignore_list_ui.dart';
|
import 'package:fluffychat/views/ui/settings_ignore_list_ui.dart';
|
||||||
import 'package:fluffychat/views/ui/settings_multiple_emotes_ui.dart';
|
import 'package:fluffychat/views/ui/settings_multiple_emotes_ui.dart';
|
||||||
import 'package:fluffychat/views/ui/settings_notifications_ui.dart';
|
import 'package:fluffychat/views/ui/settings_notifications_ui.dart';
|
||||||
import 'package:fluffychat/views/ui/settings_style_ui.dart';
|
import 'package:fluffychat/views/settings_style.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class FluffyRoutes {
|
class FluffyRoutes {
|
||||||
|
61
lib/views/settings_style.dart
Normal file
61
lib/views/settings_style.dart
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
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);
|
||||||
|
}
|
@ -1,57 +1,20 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:adaptive_theme/adaptive_theme.dart';
|
import 'package:adaptive_theme/adaptive_theme.dart';
|
||||||
import 'package:fluffychat/config/setting_keys.dart';
|
|
||||||
import 'package:fluffychat/views/widgets/max_width_body.dart';
|
import 'package:fluffychat/views/widgets/max_width_body.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
|
||||||
|
|
||||||
import '../../config/app_config.dart';
|
import '../../config/app_config.dart';
|
||||||
import '../widgets/matrix.dart';
|
import '../widgets/matrix.dart';
|
||||||
|
import '../settings_style.dart';
|
||||||
|
|
||||||
class SettingsStyle extends StatefulWidget {
|
class SettingsStyleUI extends StatelessWidget {
|
||||||
@override
|
final SettingsStyleController controller;
|
||||||
_SettingsStyleState createState() => _SettingsStyleState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SettingsStyleState extends State<SettingsStyle> {
|
const SettingsStyleUI(this.controller, {Key key}) : super(key: key);
|
||||||
void setWallpaperAction(BuildContext context) 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(BuildContext context) async {
|
|
||||||
Matrix.of(context).wallpaper = null;
|
|
||||||
await Matrix.of(context).store.deleteItem(SettingKeys.wallpaper);
|
|
||||||
setState(() => null);
|
|
||||||
}
|
|
||||||
|
|
||||||
AdaptiveThemeMode _currentTheme;
|
|
||||||
|
|
||||||
void _switchTheme(AdaptiveThemeMode newTheme, BuildContext context) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
_currentTheme ??= AdaptiveTheme.of(context).mode;
|
controller.currentTheme ??= AdaptiveTheme.of(context).mode;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: BackButton(),
|
leading: BackButton(),
|
||||||
@ -62,22 +25,22 @@ class _SettingsStyleState extends State<SettingsStyle> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
RadioListTile<AdaptiveThemeMode>(
|
RadioListTile<AdaptiveThemeMode>(
|
||||||
groupValue: _currentTheme,
|
groupValue: controller.currentTheme,
|
||||||
value: AdaptiveThemeMode.system,
|
value: AdaptiveThemeMode.system,
|
||||||
title: Text(L10n.of(context).systemTheme),
|
title: Text(L10n.of(context).systemTheme),
|
||||||
onChanged: (t) => _switchTheme(t, context),
|
onChanged: controller.switchTheme,
|
||||||
),
|
),
|
||||||
RadioListTile<AdaptiveThemeMode>(
|
RadioListTile<AdaptiveThemeMode>(
|
||||||
groupValue: _currentTheme,
|
groupValue: controller.currentTheme,
|
||||||
value: AdaptiveThemeMode.light,
|
value: AdaptiveThemeMode.light,
|
||||||
title: Text(L10n.of(context).lightTheme),
|
title: Text(L10n.of(context).lightTheme),
|
||||||
onChanged: (t) => _switchTheme(t, context),
|
onChanged: controller.switchTheme,
|
||||||
),
|
),
|
||||||
RadioListTile<AdaptiveThemeMode>(
|
RadioListTile<AdaptiveThemeMode>(
|
||||||
groupValue: _currentTheme,
|
groupValue: controller.currentTheme,
|
||||||
value: AdaptiveThemeMode.dark,
|
value: AdaptiveThemeMode.dark,
|
||||||
title: Text(L10n.of(context).darkTheme),
|
title: Text(L10n.of(context).darkTheme),
|
||||||
onChanged: (t) => _switchTheme(t, context),
|
onChanged: controller.switchTheme,
|
||||||
),
|
),
|
||||||
Divider(height: 1),
|
Divider(height: 1),
|
||||||
ListTile(
|
ListTile(
|
||||||
@ -100,13 +63,13 @@ class _SettingsStyleState extends State<SettingsStyle> {
|
|||||||
Icons.delete_forever_outlined,
|
Icons.delete_forever_outlined,
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
),
|
),
|
||||||
onTap: () => deleteWallpaperAction(context),
|
onTap: controller.deleteWallpaperAction,
|
||||||
),
|
),
|
||||||
Builder(builder: (context) {
|
Builder(builder: (context) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(L10n.of(context).changeWallpaper),
|
title: Text(L10n.of(context).changeWallpaper),
|
||||||
trailing: Icon(Icons.wallpaper_outlined),
|
trailing: Icon(Icons.wallpaper_outlined),
|
||||||
onTap: () => setWallpaperAction(context),
|
onTap: controller.setWallpaperAction,
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
Divider(height: 1),
|
Divider(height: 1),
|
||||||
@ -145,13 +108,7 @@ class _SettingsStyleState extends State<SettingsStyle> {
|
|||||||
divisions: 4,
|
divisions: 4,
|
||||||
value: AppConfig.fontSizeFactor,
|
value: AppConfig.fontSizeFactor,
|
||||||
semanticFormatterCallback: (d) => d.toString(),
|
semanticFormatterCallback: (d) => d.toString(),
|
||||||
onChanged: (d) {
|
onChanged: controller.changeFontSizeFactor,
|
||||||
setState(() => AppConfig.fontSizeFactor = d);
|
|
||||||
Matrix.of(context).store.setItem(
|
|
||||||
SettingKeys.fontSizeFactor,
|
|
||||||
AppConfig.fontSizeFactor.toString(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user