From dd502ab8cb6ff885b23085641fc8d9de6689f972 Mon Sep 17 00:00:00 2001 From: ZhuchkaTriplesix Date: Sun, 18 Oct 2026 18:54:57 +0300 Subject: [PATCH] refactor(postgresql, mysql, sqlite): read colours through context.colors; stats views drop their shadcn import (#1731) --- lib/features/mysql/mysql_connection_form.dart | 2 +- lib/features/mysql/mysql_routine_view.dart | 9 ++++----- lib/features/mysql/mysql_sql_editor_dialog.dart | 2 +- lib/features/mysql/mysql_stats_view.dart | 14 ++++++-------- lib/features/mysql/mysql_table_view.dart | 2 +- lib/features/mysql/mysql_workspace_home.dart | 6 +++--- .../postgresql/postgres_browser_views.dart | 12 ++++++------ lib/features/postgresql/postgres_routine_view.dart | 2 +- .../postgresql/postgres_sequence_view.dart | 2 +- .../postgresql/postgres_sql_editor_dialog.dart | 2 +- lib/features/postgresql/postgres_stats_view.dart | 14 ++++++-------- .../postgres_table_privileges_dialog.dart | 5 +++-- .../postgresql/postgres_table_toolbar.dart | 2 +- .../postgresql/postgres_workspace_home.dart | 6 +++--- .../postgresql/postgresql_connection_form.dart | 2 +- lib/features/sqlite/sqlite_overview_tab.dart | 8 ++++---- lib/features/sqlite/sqlite_table_view.dart | 2 +- lib/features/sqlite/sqlite_workspace_home.dart | 6 +++--- test/guards/colors_through_context_test.dart | 3 +++ test/guards/shadcn_imports_ratchet_test.dart | 2 -- 20 files changed, 50 insertions(+), 53 deletions(-) diff --git a/lib/features/mysql/mysql_connection_form.dart b/lib/features/mysql/mysql_connection_form.dart index 4238819f..4d16725d 100644 --- a/lib/features/mysql/mysql_connection_form.dart +++ b/lib/features/mysql/mysql_connection_form.dart @@ -332,7 +332,7 @@ class _MysqlConnectionFormContentState @override material.Widget build(material.BuildContext context) { - final theme = Theme.of(context).colorScheme; + final theme = context.colors; return QueryaDialogCard( constraints: WindowLayout.dialogConstraints( diff --git a/lib/features/mysql/mysql_routine_view.dart b/lib/features/mysql/mysql_routine_view.dart index 2aeb4445..334c4ae7 100644 --- a/lib/features/mysql/mysql_routine_view.dart +++ b/lib/features/mysql/mysql_routine_view.dart @@ -123,8 +123,7 @@ class _MysqlRoutineViewState extends material.State { @override material.Widget build(material.BuildContext context) { - final theme = Theme.of(context); - final cs = theme.colorScheme; + final cs = context.colors; final kindTitle = widget.isFunction ? 'Function' : 'Procedure'; return material.Column( @@ -134,10 +133,10 @@ class _MysqlRoutineViewState extends material.State { padding: const material.EdgeInsets.symmetric(horizontal: 16, vertical: 10), decoration: material.BoxDecoration( - color: theme.colorScheme.card, + color: cs.card, border: material.Border( bottom: material.BorderSide( - color: theme.colorScheme.border.withValues(alpha: 0.5), + color: cs.border.withValues(alpha: 0.5), ), ), ), @@ -146,7 +145,7 @@ class _MysqlRoutineViewState extends material.State { material.Icon( material.Icons.functions_rounded, size: 18, - color: theme.colorScheme.primary, + color: cs.primary, ), const Gap(8), material.Expanded( diff --git a/lib/features/mysql/mysql_sql_editor_dialog.dart b/lib/features/mysql/mysql_sql_editor_dialog.dart index 09d03640..5079b087 100644 --- a/lib/features/mysql/mysql_sql_editor_dialog.dart +++ b/lib/features/mysql/mysql_sql_editor_dialog.dart @@ -73,7 +73,7 @@ class _MysqlSqlEditorDialogState extends material.State<_MysqlSqlEditorDialog> { @override material.Widget build(material.BuildContext context) { - final theme = Theme.of(context).colorScheme; + final theme = context.colors; return material.Dialog( backgroundColor: material.Colors.transparent, insetPadding: WindowLayout.dialogSymmetricInsets(context), diff --git a/lib/features/mysql/mysql_stats_view.dart b/lib/features/mysql/mysql_stats_view.dart index 68ccf297..4b74e043 100644 --- a/lib/features/mysql/mysql_stats_view.dart +++ b/lib/features/mysql/mysql_stats_view.dart @@ -8,8 +8,6 @@ import 'package:querya_desktop/core/database/mysql_service.dart'; import 'package:querya_desktop/core/storage/local_db.dart'; import 'package:querya_desktop/shared/widgets/querya_sparkline.dart'; import 'package:querya_desktop/shared/widgets/widgets.dart'; -import 'package:shadcn_flutter/shadcn_flutter.dart' as shadcn - hide TextExtension; import 'package:querya_desktop/core/ui/querya_control_tokens.dart'; const _pollInterval = Duration(seconds: 5); @@ -164,7 +162,7 @@ class _MysqlStatsViewState extends material.State @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; if (_loading) { return const material.Center( @@ -260,7 +258,7 @@ class _MysqlStatsViewState extends material.State } material.Widget _header(material.BuildContext context) { - final cs = shadcn.Theme.of(context).colorScheme; + final cs = context.colors; return material.Row( children: [ material.Container( @@ -354,7 +352,7 @@ class _MysqlStatsViewState extends material.State material.Widget _summaryChips( material.BuildContext context, Map stats) { - final cs = shadcn.Theme.of(context).colorScheme; + final cs = context.colors; final versionFull = stats['version'] as String? ?? '—'; final versionShort = _extractMysqlVersion(versionFull); final uptimeSec = stats['uptime_seconds'] as int? ?? 0; @@ -436,7 +434,7 @@ class _MysqlStatsViewState extends material.State double? minHeight, bool stretchBody = false, }) { - final cs = shadcn.Theme.of(context).colorScheme; + final cs = context.colors; return material.Container( width: double.infinity, constraints: minHeight != null @@ -578,7 +576,7 @@ class _MysqlStatsViewState extends material.State final databases = stats['databases'] as List>? ?? []; if (databases.isEmpty) return const material.SizedBox.shrink(); - final cs = shadcn.Theme.of(context).colorScheme; + final cs = context.colors; return _card( context, 'Databases', @@ -637,7 +635,7 @@ class _MysqlStatsViewState extends material.State material.Widget _metricRow( material.BuildContext context, String label, String value) { - final cs = shadcn.Theme.of(context).colorScheme; + final cs = context.colors; return material.Padding( padding: const material.EdgeInsets.symmetric(vertical: 6), child: material.Row( diff --git a/lib/features/mysql/mysql_table_view.dart b/lib/features/mysql/mysql_table_view.dart index be64b60d..14cc512b 100644 --- a/lib/features/mysql/mysql_table_view.dart +++ b/lib/features/mysql/mysql_table_view.dart @@ -339,7 +339,7 @@ class _MysqlTableViewState extends material.State { onNavigateHome: widget.onNavigateHome, showExportToolbar: true, customToolbarBuilder: (ctx, state) { - final cs = Theme.of(ctx).colorScheme; + final cs = ctx.colors; final title = '$tableTitle${widget.isView ? ' (view)' : ''}'; return material.Container( diff --git a/lib/features/mysql/mysql_workspace_home.dart b/lib/features/mysql/mysql_workspace_home.dart index a1dab598..5a56dbad 100644 --- a/lib/features/mysql/mysql_workspace_home.dart +++ b/lib/features/mysql/mysql_workspace_home.dart @@ -86,7 +86,7 @@ class _MysqlWorkspaceHomeState extends material.State { @override material.Widget build(material.BuildContext context) { - final theme = Theme.of(context); + final colors = context.colors; return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ @@ -94,7 +94,7 @@ class _MysqlWorkspaceHomeState extends material.State { constraints: const material.BoxConstraints(minHeight: 44), padding: const material.EdgeInsets.symmetric(horizontal: 12), decoration: material.BoxDecoration( - color: theme.colorScheme.muted.withValues(alpha: 0.6), + color: colors.muted.withValues(alpha: 0.6), ), child: material.Row( children: [ @@ -104,7 +104,7 @@ class _MysqlWorkspaceHomeState extends material.State { material.Icon( material.Icons.lock_outline_rounded, size: 14, - color: theme.colorScheme.mutedForeground, + color: colors.mutedForeground, ), ], if (widget.lastSelectedMysqlObject != null && diff --git a/lib/features/postgresql/postgres_browser_views.dart b/lib/features/postgresql/postgres_browser_views.dart index 45a0b238..a8eb0f40 100644 --- a/lib/features/postgresql/postgres_browser_views.dart +++ b/lib/features/postgresql/postgres_browser_views.dart @@ -89,7 +89,7 @@ class _PostgresIndexListViewState @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; if (_loading) { return material.Container( color: cs.background, @@ -264,7 +264,7 @@ class _PostgresTriggerListViewState @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; if (_loading) { return material.Container( color: cs.background, @@ -431,7 +431,7 @@ class _PostgresTypeListViewState extends material.State { @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; if (_loading) { return const material.Center( child: QueryaSpinner(size: QueryaSpinnerSize.md), @@ -578,7 +578,7 @@ class _PostgresExtensionListViewState @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; if (_loading) { return const material.Center( child: QueryaSpinner(size: QueryaSpinnerSize.md), @@ -722,7 +722,7 @@ class _PostgresFdwListViewState extends material.State { @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; if (_loading) { return const material.Center( child: QueryaSpinner(size: QueryaSpinnerSize.md), @@ -832,7 +832,7 @@ material.Widget _browserToolbar( required String title, required VoidCallback onRefresh, }) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; return material.Container( padding: const material.EdgeInsets.fromLTRB(16, 10, 16, 10), decoration: material.BoxDecoration( diff --git a/lib/features/postgresql/postgres_routine_view.dart b/lib/features/postgresql/postgres_routine_view.dart index 334fffa7..bc06d4f8 100644 --- a/lib/features/postgresql/postgres_routine_view.dart +++ b/lib/features/postgresql/postgres_routine_view.dart @@ -129,7 +129,7 @@ class _PostgresRoutineViewState extends material.State { @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; if (_loading) { return material.Container( diff --git a/lib/features/postgresql/postgres_sequence_view.dart b/lib/features/postgresql/postgres_sequence_view.dart index 5adfdef2..381f7d1a 100644 --- a/lib/features/postgresql/postgres_sequence_view.dart +++ b/lib/features/postgresql/postgres_sequence_view.dart @@ -112,7 +112,7 @@ class _PostgresSequenceViewState extends material.State { @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; if (_loading) { return material.Container( diff --git a/lib/features/postgresql/postgres_sql_editor_dialog.dart b/lib/features/postgresql/postgres_sql_editor_dialog.dart index 0d961fad..8f74db21 100644 --- a/lib/features/postgresql/postgres_sql_editor_dialog.dart +++ b/lib/features/postgresql/postgres_sql_editor_dialog.dart @@ -75,7 +75,7 @@ class _PostgresSqlEditorDialogState @override material.Widget build(material.BuildContext context) { - final theme = Theme.of(context).colorScheme; + final theme = context.colors; return material.Dialog( backgroundColor: material.Colors.transparent, insetPadding: WindowLayout.dialogSymmetricInsets(context), diff --git a/lib/features/postgresql/postgres_stats_view.dart b/lib/features/postgresql/postgres_stats_view.dart index 0381db13..a5e79406 100644 --- a/lib/features/postgresql/postgres_stats_view.dart +++ b/lib/features/postgresql/postgres_stats_view.dart @@ -9,8 +9,6 @@ import 'package:querya_desktop/core/database/postgres_service.dart'; import 'package:querya_desktop/core/storage/local_db.dart'; import 'package:querya_desktop/shared/widgets/querya_sparkline.dart'; import 'package:querya_desktop/shared/widgets/widgets.dart'; -import 'package:shadcn_flutter/shadcn_flutter.dart' as shadcn - hide TextExtension; import 'package:querya_desktop/core/ui/querya_control_tokens.dart'; const _pollInterval = Duration(seconds: 5); @@ -202,7 +200,7 @@ class _PostgresStatsViewState extends material.State @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; if (_loading) { return const material.Center( @@ -301,7 +299,7 @@ class _PostgresStatsViewState extends material.State } material.Widget _header(material.BuildContext context) { - final cs = shadcn.Theme.of(context).colorScheme; + final cs = context.colors; return material.LayoutBuilder( builder: (context, constraints) { return material.SingleChildScrollView( @@ -369,7 +367,7 @@ class _PostgresStatsViewState extends material.State material.Widget _summaryChips( material.BuildContext context, Map stats) { - final cs = shadcn.Theme.of(context).colorScheme; + final cs = context.colors; final versionFull = stats['version'] as String? ?? '—'; final versionShort = _extractPgVersion(versionFull); final settings = stats['settings'] as Map? ?? {}; @@ -451,7 +449,7 @@ class _PostgresStatsViewState extends material.State material.Widget _card( material.BuildContext context, String title, material.Widget body, {double? minHeight}) { - final cs = shadcn.Theme.of(context).colorScheme; + final cs = context.colors; return material.Container( width: double.infinity, constraints: minHeight != null @@ -535,7 +533,7 @@ class _PostgresStatsViewState extends material.State final databases = stats['databases'] as List>? ?? []; if (databases.isEmpty) return const material.SizedBox.shrink(); - final cs = shadcn.Theme.of(context).colorScheme; + final cs = context.colors; return _card( context, 'Databases', @@ -609,7 +607,7 @@ class _PostgresStatsViewState extends material.State material.Widget _row( material.BuildContext context, String key, String value) { - final cs = shadcn.Theme.of(context).colorScheme; + final cs = context.colors; return material.Padding( padding: const material.EdgeInsets.symmetric(vertical: 4), child: material.Row( diff --git a/lib/features/postgresql/postgres_table_privileges_dialog.dart b/lib/features/postgresql/postgres_table_privileges_dialog.dart index 10ddd3ce..ac55f2e7 100644 --- a/lib/features/postgresql/postgres_table_privileges_dialog.dart +++ b/lib/features/postgresql/postgres_table_privileges_dialog.dart @@ -3,6 +3,7 @@ import 'package:querya_desktop/core/database/postgres_connection.dart'; import 'package:querya_desktop/core/layout/window_layout.dart'; import 'package:querya_desktop/core/database/postgres_metadata.dart'; import 'package:querya_desktop/core/theme/querya_typography.dart'; +import 'package:querya_desktop/core/theme/querya_ui_colors.dart'; import 'package:querya_desktop/shared/widgets/widgets.dart'; import 'package:querya_desktop/core/ui/querya_control_tokens.dart'; @@ -78,7 +79,7 @@ class _PrivilegesDialogBodyState extends material.State<_PrivilegesDialogBody> { @override material.Widget build(material.BuildContext context) { - final theme = Theme.of(context).colorScheme; + final theme = context.colors; final mq = material.MediaQuery.sizeOf(context); final hInset = WindowLayout.dialogVerticalInset(mq.height) * 2; final wInset = WindowLayout.dialogHorizontalInset(mq.width) * 2; @@ -167,7 +168,7 @@ class _PrivilegesDialogBodyState extends material.State<_PrivilegesDialogBody> { ); } - material.Widget _buildListArea(ColorScheme theme) { + material.Widget _buildListArea(QueryaUiColors theme) { if (_loading) { return const material.Center( child: QueryaSpinner(size: QueryaSpinnerSize.md), diff --git a/lib/features/postgresql/postgres_table_toolbar.dart b/lib/features/postgresql/postgres_table_toolbar.dart index f9cf90fb..05295878 100644 --- a/lib/features/postgresql/postgres_table_toolbar.dart +++ b/lib/features/postgresql/postgres_table_toolbar.dart @@ -47,7 +47,7 @@ class PostgresTableToolbar extends material.StatelessWidget { @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; return material.Container( padding: const material.EdgeInsets.fromLTRB(16, 10, 16, 10), decoration: material.BoxDecoration( diff --git a/lib/features/postgresql/postgres_workspace_home.dart b/lib/features/postgresql/postgres_workspace_home.dart index 4c051c42..45ac297c 100644 --- a/lib/features/postgresql/postgres_workspace_home.dart +++ b/lib/features/postgresql/postgres_workspace_home.dart @@ -101,7 +101,7 @@ class _PostgresWorkspaceHomeState @override material.Widget build(material.BuildContext context) { - final theme = Theme.of(context); + final colors = context.colors; return Column( crossAxisAlignment: material.CrossAxisAlignment.stretch, children: [ @@ -109,7 +109,7 @@ class _PostgresWorkspaceHomeState constraints: const material.BoxConstraints(minHeight: 44), padding: const material.EdgeInsets.symmetric(horizontal: 12), decoration: material.BoxDecoration( - color: theme.colorScheme.muted.withValues(alpha: 0.6), + color: colors.muted.withValues(alpha: 0.6), ), child: material.Row( children: [ @@ -119,7 +119,7 @@ class _PostgresWorkspaceHomeState material.Icon( material.Icons.lock_outline_rounded, size: 14, - color: theme.colorScheme.mutedForeground, + color: colors.mutedForeground, ), ], if (widget.lastSelectedPostgresObject != null && diff --git a/lib/features/postgresql/postgresql_connection_form.dart b/lib/features/postgresql/postgresql_connection_form.dart index 5b5e7bf3..358c7c39 100644 --- a/lib/features/postgresql/postgresql_connection_form.dart +++ b/lib/features/postgresql/postgresql_connection_form.dart @@ -484,7 +484,7 @@ class _PostgresConnectionFormContentState @override material.Widget build(material.BuildContext context) { - final theme = Theme.of(context).colorScheme; + final theme = context.colors; return QueryaDialogCard( constraints: WindowLayout.dialogConstraints( diff --git a/lib/features/sqlite/sqlite_overview_tab.dart b/lib/features/sqlite/sqlite_overview_tab.dart index 637321ca..904a283f 100644 --- a/lib/features/sqlite/sqlite_overview_tab.dart +++ b/lib/features/sqlite/sqlite_overview_tab.dart @@ -134,7 +134,7 @@ class _SqliteOverviewTabState extends material.State { @override material.Widget build(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; if (_loading && _overview == null) { return const material.Center( @@ -217,7 +217,7 @@ class _SqliteOverviewTabState extends material.State { } material.Widget _header(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; final name = widget.connectionRow.name; final path = widget.connectionRow.host ?? 'in-memory'; return material.Row( @@ -280,7 +280,7 @@ class _SqliteOverviewTabState extends material.State { int pageCount, int pageSize, ) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; material.Widget chip(String label, String value, material.IconData icon) { return material.Expanded( @@ -345,7 +345,7 @@ class _SqliteOverviewTabState extends material.State { } material.Widget _tablesCard(material.BuildContext context) { - final cs = Theme.of(context).colorScheme; + final cs = context.colors; return material.Container( decoration: material.BoxDecoration( color: cs.card, diff --git a/lib/features/sqlite/sqlite_table_view.dart b/lib/features/sqlite/sqlite_table_view.dart index debbae35..73034080 100644 --- a/lib/features/sqlite/sqlite_table_view.dart +++ b/lib/features/sqlite/sqlite_table_view.dart @@ -379,7 +379,7 @@ class _SqliteTableViewState extends material.State { onNavigateHome: widget.onNavigateHome, showExportToolbar: true, customToolbarBuilder: (ctx, state) { - final cs = Theme.of(ctx).colorScheme; + final cs = ctx.colors; final title = '${widget.tableName}${widget.isView ? ' (view)' : ''}'; return material.Container( diff --git a/lib/features/sqlite/sqlite_workspace_home.dart b/lib/features/sqlite/sqlite_workspace_home.dart index fc7090db..9077a929 100644 --- a/lib/features/sqlite/sqlite_workspace_home.dart +++ b/lib/features/sqlite/sqlite_workspace_home.dart @@ -78,7 +78,7 @@ class _SqliteWorkspaceHomeState extends material.State { @override material.Widget build(material.BuildContext context) { - final theme = Theme.of(context); + final colors = context.colors; return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ @@ -86,7 +86,7 @@ class _SqliteWorkspaceHomeState extends material.State { constraints: const material.BoxConstraints(minHeight: 44), padding: const material.EdgeInsets.symmetric(horizontal: 12), decoration: material.BoxDecoration( - color: theme.colorScheme.muted.withValues(alpha: 0.6), + color: colors.muted.withValues(alpha: 0.6), ), child: material.Row( children: [ @@ -96,7 +96,7 @@ class _SqliteWorkspaceHomeState extends material.State { material.Icon( material.Icons.lock_outline_rounded, size: 14, - color: theme.colorScheme.mutedForeground, + color: colors.mutedForeground, ), ], if (widget.lastSelectedSqliteObject != null && diff --git a/test/guards/colors_through_context_test.dart b/test/guards/colors_through_context_test.dart index 7f806430..43f24175 100644 --- a/test/guards/colors_through_context_test.dart +++ b/test/guards/colors_through_context_test.dart @@ -10,8 +10,11 @@ void main() { const migrated = [ 'lib/features/connections', 'lib/features/mongodb', + 'lib/features/mysql', + 'lib/features/postgresql', 'lib/features/redis', 'lib/features/settings', + 'lib/features/sqlite', 'lib/features/workspace', ]; diff --git a/test/guards/shadcn_imports_ratchet_test.dart b/test/guards/shadcn_imports_ratchet_test.dart index a651eced..59c2677f 100644 --- a/test/guards/shadcn_imports_ratchet_test.dart +++ b/test/guards/shadcn_imports_ratchet_test.dart @@ -35,8 +35,6 @@ void main() { 'lib/features/mongodb/mongo_document_tree_view.dart', 'lib/features/mongodb/mongo_documents_json_view.dart', 'lib/features/mongodb/mongo_documents_table_view.dart', - 'lib/features/mysql/mysql_stats_view.dart', - 'lib/features/postgresql/postgres_stats_view.dart', 'lib/features/settings/preferences_controls.dart', 'lib/features/updater/update_changelog_view.dart', 'lib/features/workspace/data_grid_calc_bar.dart',