Fix text color not resolving when CupertinoThemeData.brightness is null (#115026)
* Fix text color not resolving in `CupertinoApp` * Make linter happy * Create cupertinoBuilder for theming * Make linter happy * Fix tests * Fix regression * Delete whitespace * Resolve color passed to the `WidgetsApp` * Revert "Resolve color passed to the `WidgetsApp`" This reverts commit 6994719a564c476dcb6d389e4547bff3ded08203. * Resolve selection colors * Kick tests * Delete doubled test
This commit is contained in:
@@ -558,6 +558,7 @@ class _CupertinoAppState extends State<CupertinoApp> {
|
||||
restorationScopeId: widget.restorationScopeId,
|
||||
);
|
||||
}
|
||||
|
||||
return WidgetsApp(
|
||||
key: GlobalObjectKey(this),
|
||||
navigatorKey: widget.navigatorKey,
|
||||
@@ -595,7 +596,7 @@ class _CupertinoAppState extends State<CupertinoApp> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final CupertinoThemeData effectiveThemeData = widget.theme ?? const CupertinoThemeData();
|
||||
final CupertinoThemeData effectiveThemeData = (widget.theme ?? const CupertinoThemeData()).resolveFrom(context);
|
||||
|
||||
return ScrollConfiguration(
|
||||
behavior: widget.scrollBehavior ?? const CupertinoScrollBehavior(),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@@ -332,6 +333,97 @@ void main() {
|
||||
);
|
||||
expect(capturedContext.dependOnInheritedWidgetOfExactType<MediaQuery>()?.key, uniqueKey);
|
||||
});
|
||||
|
||||
testWidgets('Text color is correctly resolved when CupertinoThemeData.brightness is null', (WidgetTester tester) async {
|
||||
debugBrightnessOverride = Brightness.dark;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: Text('Hello'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final RenderParagraph paragraph = tester.renderObject(find.text('Hello'));
|
||||
final CupertinoDynamicColor textColor = paragraph.text.style!.color! as CupertinoDynamicColor;
|
||||
|
||||
// App with non-null brightness, so resolving color
|
||||
// doesn't depend on the MediaQuery.platformBrightness.
|
||||
late BuildContext capturedContext;
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
theme: const CupertinoThemeData(
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
capturedContext = context;
|
||||
|
||||
return const Placeholder();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// We expect the string representations of the colors to have darkColor indicated (*) as effective color.
|
||||
// (color = Color(0xff000000), *darkColor = Color(0xffffffff)*, resolved by: Builder)
|
||||
expect(textColor.toString(), CupertinoColors.label.resolveFrom(capturedContext).toString());
|
||||
|
||||
debugBrightnessOverride = null;
|
||||
});
|
||||
|
||||
testWidgets('Cursor color is resolved when CupertinoThemeData.brightness is null', (WidgetTester tester) async {
|
||||
debugBrightnessOverride = Brightness.dark;
|
||||
|
||||
RenderEditable findRenderEditable(WidgetTester tester) {
|
||||
final RenderObject root = tester.renderObject(find.byType(EditableText));
|
||||
expect(root, isNotNull);
|
||||
|
||||
RenderEditable? renderEditable;
|
||||
void recursiveFinder(RenderObject child) {
|
||||
if (child is RenderEditable) {
|
||||
renderEditable = child;
|
||||
return;
|
||||
}
|
||||
child.visitChildren(recursiveFinder);
|
||||
}
|
||||
|
||||
root.visitChildren(recursiveFinder);
|
||||
expect(renderEditable, isNotNull);
|
||||
return renderEditable!;
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
theme: const CupertinoThemeData(
|
||||
primaryColor: CupertinoColors.activeOrange,
|
||||
),
|
||||
home: CupertinoPageScaffold(
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return EditableText(
|
||||
backgroundCursorColor: DefaultSelectionStyle.of(context).selectionColor!,
|
||||
cursorColor: DefaultSelectionStyle.of(context).cursorColor!,
|
||||
controller: TextEditingController(),
|
||||
focusNode: FocusNode(),
|
||||
style: const TextStyle(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final RenderEditable editableText = findRenderEditable(tester);
|
||||
final Color cursorColor = editableText.cursorColor!;
|
||||
|
||||
// Cursor color should be equal to the dark variant of the primary color.
|
||||
// Alpha value needs to be 0, because cursor is not visible by default.
|
||||
expect(cursorColor, CupertinoColors.activeOrange.darkColor.withAlpha(0));
|
||||
|
||||
debugBrightnessOverride = null;
|
||||
});
|
||||
}
|
||||
|
||||
class MockScrollBehavior extends ScrollBehavior {
|
||||
|
||||
Reference in New Issue
Block a user