mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-27 23:09:35 +01:00
refactor: Make style settings null safe
This commit is contained in:
parent
03aabec300
commit
1ba2d49c21
@ -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();
|
||||
|
@ -1,3 +1,5 @@
|
||||
//@dart=2.12
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adaptive_theme/adaptive_theme.dart';
|
||||
@ -11,7 +13,7 @@ import 'settings_style.dart';
|
||||
class SettingsStyleView extends StatelessWidget {
|
||||
final SettingsStyleController controller;
|
||||
|
||||
const SettingsStyleView(this.controller, {Key key}) : super(key: key);
|
||||
const SettingsStyleView(this.controller, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -20,7 +22,7 @@ class SettingsStyleView extends StatelessWidget {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: const BackButton(),
|
||||
title: Text(L10n.of(context).changeTheme),
|
||||
title: Text(L10n.of(context)!.changeTheme),
|
||||
),
|
||||
body: MaxWidthBody(
|
||||
withScrolling: true,
|
||||
@ -59,25 +61,25 @@ class SettingsStyleView extends StatelessWidget {
|
||||
RadioListTile<AdaptiveThemeMode>(
|
||||
groupValue: controller.currentTheme,
|
||||
value: AdaptiveThemeMode.system,
|
||||
title: Text(L10n.of(context).systemTheme),
|
||||
title: Text(L10n.of(context)!.systemTheme),
|
||||
onChanged: controller.switchTheme,
|
||||
),
|
||||
RadioListTile<AdaptiveThemeMode>(
|
||||
groupValue: controller.currentTheme,
|
||||
value: AdaptiveThemeMode.light,
|
||||
title: Text(L10n.of(context).lightTheme),
|
||||
title: Text(L10n.of(context)!.lightTheme),
|
||||
onChanged: controller.switchTheme,
|
||||
),
|
||||
RadioListTile<AdaptiveThemeMode>(
|
||||
groupValue: controller.currentTheme,
|
||||
value: AdaptiveThemeMode.dark,
|
||||
title: Text(L10n.of(context).darkTheme),
|
||||
title: Text(L10n.of(context)!.darkTheme),
|
||||
onChanged: controller.switchTheme,
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
L10n.of(context).wallpaper,
|
||||
L10n.of(context)!.wallpaper,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
fontWeight: FontWeight.bold,
|
||||
@ -99,10 +101,10 @@ class SettingsStyleView extends StatelessWidget {
|
||||
),
|
||||
Builder(builder: (context) {
|
||||
return ListTile(
|
||||
title: Text(L10n.of(context).changeWallpaper),
|
||||
title: Text(L10n.of(context)!.changeWallpaper),
|
||||
trailing: Icon(
|
||||
Icons.photo_outlined,
|
||||
color: Theme.of(context).textTheme.bodyText1.color,
|
||||
color: Theme.of(context).textTheme.bodyText1?.color,
|
||||
),
|
||||
onTap: controller.setWallpaperAction,
|
||||
);
|
||||
@ -110,7 +112,7 @@ class SettingsStyleView extends StatelessWidget {
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
L10n.of(context).fontSize,
|
||||
L10n.of(context)!.fontSize,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
@ -71,8 +71,10 @@ class StoryView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
if (!controller.isOwnStory && currentEvent != null)
|
||||
actions: currentEvent == null
|
||||
? null
|
||||
: [
|
||||
if (!controller.isOwnStory)
|
||||
AnimatedOpacity(
|
||||
duration: const Duration(seconds: 1),
|
||||
opacity: controller.isHold ? 0 : 1,
|
||||
|
Loading…
Reference in New Issue
Block a user