From 2782045a6ee5bd8ed278f1cbd98f595e94ac6f1e Mon Sep 17 00:00:00 2001 From: ZhuchkaTriplesix Date: Sat, 17 Oct 2026 07:11:57 +0300 Subject: [PATCH] fix(theme): token defaults without a theme scope no longer need a shadcn theme #1666 (#1509) made the dialog backdrop use workbenchOrDefault.shadow. Without a QueryaThemeScope that getter fell back to colors.brightness, which is shadcn Theme.of and asserts when there is no shadcn theme, so every app_dialog test (a bare MaterialApp) failed and dev went red. The fallbacks of workbenchOrDefault, editorTheme and semanticPalette take the shadcn theme's brightness when there is one, else Material's. The app always has both scopes, so nothing changes there. The settled-tint test now expects the theme's shadow colour, which the backdrop has used since #1666, instead of plain black. --- lib/core/theme/querya_theme_scope.dart | 17 ++++++++++++++--- test/shared/app_dialog_test.dart | 7 ++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/core/theme/querya_theme_scope.dart b/lib/core/theme/querya_theme_scope.dart index 546ca1d2..4b3ed85e 100644 --- a/lib/core/theme/querya_theme_scope.dart +++ b/lib/core/theme/querya_theme_scope.dart @@ -59,6 +59,17 @@ extension QueryaThemeContext on BuildContext { QueryaTheme get queryaTheme => QueryaThemeScope.of(this); + /// The brightness the defaults below follow when there is no + /// [QueryaThemeScope]: the shadcn theme's, else Material's. [colors] asserts + /// without a shadcn theme, and these defaults exist for exactly that case + /// (a widget under a bare app, as in tests). + Brightness get _ambientBrightness => + dependOnInheritedWidgetOfExactType() + ?.data + .colorScheme + .brightness ?? + material.Theme.of(this).brightness; + QueryaWorkbenchTheme get workbench => workbenchOrDefault; /// The workbench tokens of the nearest [QueryaThemeScope], or the defaults @@ -67,20 +78,20 @@ extension QueryaThemeContext on BuildContext { /// scope. QueryaWorkbenchTheme get workbenchOrDefault => QueryaThemeScope.maybeOf(this)?.workbench ?? - (colors.brightness == Brightness.light + (_ambientBrightness == Brightness.light ? QueryaWorkbenchTheme.lightDefault : QueryaWorkbenchTheme.darkDefault); QueryaEditorTheme get editorTheme => QueryaThemeScope.maybeOf(this)?.editor ?? - (colors.brightness == Brightness.light + (_ambientBrightness == Brightness.light ? QueryaEditorTheme.lightDefault : QueryaEditorTheme.darkDefault); QueryaSemanticPalette get semanticPalette => QueryaSemanticPalette.fromTheme( QueryaThemeScope.maybeOf(this) ?? - (colors.brightness == Brightness.light + (_ambientBrightness == Brightness.light ? QueryaTheme.lightDefault : QueryaTheme.darkDefault), ); diff --git a/test/shared/app_dialog_test.dart b/test/shared/app_dialog_test.dart index 576e01fd..49fde364 100644 --- a/test/shared/app_dialog_test.dart +++ b/test/shared/app_dialog_test.dart @@ -4,6 +4,7 @@ import 'dart:ui' show ImageFilter; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:querya_desktop/core/theme/querya_theme_scope.dart'; import 'package:querya_desktop/core/motion/querya_motion.dart'; import 'package:querya_desktop/core/motion/querya_motion_scope.dart'; import 'package:querya_desktop/shared/widgets/app_dialog.dart'; @@ -180,7 +181,11 @@ void main() { final filter = tester.widget(find.byType(BackdropFilter)); expect(filter.filter, fullFilter); - expect(tintOf(tester), fullTint); + // The tint is the theme's shadow colour (#1509), at full alpha here. + expect( + tintOf(tester), + ctx.workbenchOrDefault.shadow.withValues(alpha: fullTint.a), + ); expect( find.ancestor( of: find.byType(BackdropFilter),