refactor: Make style settings null safe
This commit is contained in:
parent
5de0c2bfba
commit
5205e89cdb
3 changed files with 50 additions and 42 deletions
|
|
@ -1,3 +1,5 @@
|
|||
//@dart=2.12
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -12,7 +14,7 @@ import '../../widgets/matrix.dart';
|
|||
import 'settings_style_view.dart';
|
||||
|
||||
class SettingsStyle extends StatefulWidget {
|
||||
const SettingsStyle({Key key}) : super(key: key);
|
||||
const SettingsStyle({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
SettingsStyleController createState() => SettingsStyleController();
|
||||
|
|
@ -22,18 +24,19 @@ class SettingsStyleController extends State<SettingsStyle> {
|
|||
void setWallpaperAction() async {
|
||||
final wallpaper =
|
||||
await FilePickerCross.importFromStorage(type: FileTypeCross.image);
|
||||
if (wallpaper == null) return;
|
||||
Matrix.of(context).wallpaper = File(wallpaper.path);
|
||||
final path = wallpaper.path;
|
||||
if (path == null) return;
|
||||
Matrix.of(context).wallpaper = File(path);
|
||||
await Matrix.of(context)
|
||||
.store
|
||||
.setItem(SettingKeys.wallpaper, wallpaper.path);
|
||||
setState(() => null);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void deleteWallpaperAction() async {
|
||||
Matrix.of(context).wallpaper = null;
|
||||
await Matrix.of(context).store.deleteItem(SettingKeys.wallpaper);
|
||||
setState(() => null);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void setChatColor(Color color) async {
|
||||
|
|
@ -48,7 +51,7 @@ class SettingsStyleController extends State<SettingsStyle> {
|
|||
);
|
||||
}
|
||||
|
||||
AdaptiveThemeMode currentTheme;
|
||||
AdaptiveThemeMode? currentTheme;
|
||||
|
||||
static final List<Color> customColors = [
|
||||
AppConfig.primaryColor,
|
||||
|
|
@ -59,7 +62,8 @@ class SettingsStyleController extends State<SettingsStyle> {
|
|||
Colors.blueGrey.shade600,
|
||||
];
|
||||
|
||||
void switchTheme(AdaptiveThemeMode newTheme) {
|
||||
void switchTheme(AdaptiveThemeMode? newTheme) {
|
||||
if (newTheme == null) return;
|
||||
switch (newTheme) {
|
||||
case AdaptiveThemeMode.light:
|
||||
AdaptiveTheme.of(context).setLight();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue