Reland "Add BuildContext parameter to TextEditingController.buildTextSpan" (#73510)

This commit is contained in:
Jesse
2021-01-28 18:49:03 +01:00
committed by GitHub
parent d40f4399e2
commit 2e7ab87a4d
3 changed files with 32 additions and 2 deletions

View File

@@ -5810,6 +5810,25 @@ void main() {
}),
);
});
testWidgets('TextEditingController.buildTextSpan receives build context', (WidgetTester tester) async {
final _AccentColorTextEditingController controller = _AccentColorTextEditingController('a');
const Color color = Color.fromARGB(255, 1, 2, 3);
await tester.pumpWidget(MaterialApp(
theme: ThemeData.light().copyWith(accentColor: color),
home: EditableText(
controller: controller,
focusNode: FocusNode(),
style: Typography.material2018(platform: TargetPlatform.android).black.subtitle1!,
cursorColor: Colors.blue,
backgroundCursorColor: Colors.grey,
),
));
final RenderEditable renderEditable = findRenderEditable(tester);
final TextSpan textSpan = renderEditable.text!;
expect(textSpan.style!.color, color);
});
});
testWidgets('autofocus:true on first frame does not throw', (WidgetTester tester) async {
@@ -7286,3 +7305,13 @@ class SkipPaintingRenderObject extends RenderProxyBox {
@override
void paint(PaintingContext context, Offset offset) { }
}
class _AccentColorTextEditingController extends TextEditingController {
_AccentColorTextEditingController(String text) : super(text: text);
@override
TextSpan buildTextSpan({required BuildContext context, TextStyle? style, required bool withComposing}) {
final Color color = Theme.of(context).accentColor;
return super.buildTextSpan(context: context, style: TextStyle(color: color), withComposing: withComposing);
}
}