From 57947eabe67af410f6b2b7ed05db0aa5aee3bb49 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Fri, 5 Jun 2026 14:47:36 +0200 Subject: [PATCH] Don't default to black text Otherwise this might be unreadable on dark mode --- lib/core/error_dialogs.dart | 12 ++++---- test/core/error_dialogs_test.dart | 46 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 test/core/error_dialogs_test.dart diff --git a/lib/core/error_dialogs.dart b/lib/core/error_dialogs.dart index 2cfc4fb3e..6ff9b6b5b 100644 --- a/lib/core/error_dialogs.dart +++ b/lib/core/error_dialogs.dart @@ -421,7 +421,6 @@ void showDeleteLogDialog(BuildContext context, String confirmDeleteName, Log log /// Processes the error messages from the server and returns a list of widgets List formatApiErrors(List errors, {Color? color}) { final logger = Logger('formatApiErrors'); - final textColor = color ?? Colors.black; final List errorList = []; @@ -429,13 +428,13 @@ List formatApiErrors(List errors, {Color? color}) { errorList.add( Text( error.key, - style: TextStyle(fontWeight: FontWeight.bold, color: textColor), + style: TextStyle(fontWeight: FontWeight.bold, color: color), ), ); logger.warning(error.errorMessages); for (final message in error.errorMessages) { - errorList.add(Text(message, style: TextStyle(color: textColor))); + errorList.add(Text(message, style: TextStyle(color: color))); } errorList.add(const SizedBox(height: 8)); } @@ -445,21 +444,20 @@ List formatApiErrors(List errors, {Color? color}) { /// Processes the error messages from the server and returns a list of widgets List formatTextErrors(List errors, {String? title, Color? color}) { - final textColor = color ?? Colors.black; - final List errorList = []; + // A null color inherits the surrounding text style (readable in dark mode). if (title != null) { errorList.add( Text( title, - style: TextStyle(fontWeight: FontWeight.bold, color: textColor), + style: TextStyle(fontWeight: FontWeight.bold, color: color), ), ); } for (final message in errors) { - errorList.add(Text(message, style: TextStyle(color: textColor))); + errorList.add(Text(message, style: TextStyle(color: color))); } errorList.add(const SizedBox(height: 8)); diff --git a/test/core/error_dialogs_test.dart b/test/core/error_dialogs_test.dart new file mode 100644 index 000000000..417696ef7 --- /dev/null +++ b/test/core/error_dialogs_test.dart @@ -0,0 +1,46 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:wger/core/error_dialogs.dart'; +import 'package:wger/helpers/errors.dart'; + +void main() { + group('formatApiErrors', () { + final errors = [ + ApiError(key: 'username', errorMessages: ['too short', 'already taken']), + ]; + + test('leaves the text color unset so it inherits the theme (dark-mode readable)', () { + // Hardcoding a color (the old Colors.black default) made the API error + // dialog unreadable on a dark background. A null color inherits instead. + final texts = formatApiErrors(errors).whereType().toList(); + + expect(texts, isNotEmpty); + expect(texts.every((t) => t.style?.color == null), isTrue); + }); + + test('applies an explicit color when one is given', () { + final texts = formatApiErrors(errors, color: Colors.red).whereType().toList(); + + expect(texts, isNotEmpty); + expect(texts.every((t) => t.style?.color == Colors.red), isTrue); + }); + }); +}