From d3148ab89d3aa78ba4d014acf8383e0d96d1d49e Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 9 Dec 2024 22:57:20 +0800 Subject: [PATCH] :lipstick: Increase the appbar opacity when has background image --- lib/screens/settings.dart | 2 ++ lib/theme.dart | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 78d6f63..219a17e 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -78,6 +78,7 @@ class _SettingsScreenState extends State { if (image == null) return; await File(image.path).copy('$_docBasepath/app_background_image'); + _prefs?.setBool('has_background_image', true); setState(() {}); }, @@ -98,6 +99,7 @@ class _SettingsScreenState extends State { trailing: const Icon(Symbols.chevron_right), onTap: () { File('$_docBasepath/app_background_image').deleteSync(); + _prefs?.remove('has_background_image'); setState(() {}); }, ); diff --git a/lib/theme.dart b/lib/theme.dart index 9575efd..bec7f77 100644 --- a/lib/theme.dart +++ b/lib/theme.dart @@ -1,4 +1,8 @@ +import 'dart:io'; + +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:path_provider/path_provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; const kMaterialYouToggleStoreKey = 'app_theme_material_you'; @@ -28,9 +32,10 @@ Future createAppTheme( brightness: brightness, ); + final hasBackground = prefs.getBool('has_background_image') ?? false; + return ThemeData( - useMaterial3: - useMaterial3 ?? (prefs.getBool(kMaterialYouToggleStoreKey) ?? false), + useMaterial3: useMaterial3 ?? (prefs.getBool(kMaterialYouToggleStoreKey) ?? false), colorScheme: colorScheme, brightness: brightness, iconTheme: IconThemeData( @@ -41,6 +46,8 @@ Future createAppTheme( ), appBarTheme: AppBarTheme( centerTitle: true, + backgroundColor: hasBackground ? colorScheme.primary.withOpacity(0.75) : colorScheme.primary, + foregroundColor: colorScheme.onPrimary, ), scaffoldBackgroundColor: Colors.transparent, );