From c733864aff0393b432570a5c92d7fd4e69cb67da Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Thu, 14 May 2020 11:02:07 -0700 Subject: [PATCH] Step 1 of 3: Add opt-in for debugCheckHasMaterialLocalizations assertion on TextField (#56090) --- .../flutter/lib/src/material/text_field.dart | 20 +++++++++++++++++-- .../test/widgets/physical_model_test.dart | 18 +++++++---------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index 7fef72632a3..3485a5f6a17 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// TODO(Piinks): Remove ignoring deprecated member use analysis +// when TextField.canAssertMaterialLocalizations parameter is removed. +// ignore_for_file: deprecated_member_use_from_same_package + import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle; import 'package:flutter/cupertino.dart'; @@ -348,6 +352,7 @@ class TextField extends StatefulWidget { this.scrollController, this.scrollPhysics, this.autofillHints, + bool canAssertMaterialLocalizations, }) : assert(textAlign != null), assert(readOnly != null), assert(autofocus != null), @@ -393,6 +398,7 @@ class TextField extends StatefulWidget { selectAll: true, paste: true, )), + canAssertMaterialLocalizations = canAssertMaterialLocalizations ?? false, super(key: key); /// Controls the text being edited. @@ -724,6 +730,16 @@ class TextField extends StatefulWidget { /// {@macro flutter.widgets.editableText.autofillHints} final Iterable autofillHints; + /// Indicates whether [debugCheckHasMaterialLocalizations] can be called + /// during build. + @Deprecated( + 'Set canAssertMaterialLocalizations to `true`. This parameter will be ' + 'removed and was introduced to migrate TextField to assert ' + 'debugCheckHasMaterialLocalizations by default. ' + 'This feature was deprecated after v1.18.0.' + ) + final bool canAssertMaterialLocalizations; + @override _TextFieldState createState() => _TextFieldState(); @@ -964,8 +980,8 @@ class _TextFieldState extends State implements TextSelectionGestureDe @override Widget build(BuildContext context) { assert(debugCheckHasMaterial(context)); - // TODO(jonahwilliams): uncomment out this check once we have migrated tests. - // assert(debugCheckHasMaterialLocalizations(context)); + if (widget.canAssertMaterialLocalizations) + assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasDirectionality(context)); assert( !(widget.style != null && widget.style.inherit == false && diff --git a/packages/flutter/test/widgets/physical_model_test.dart b/packages/flutter/test/widgets/physical_model_test.dart index 0991e36da2b..97174839f6c 100644 --- a/packages/flutter/test/widgets/physical_model_test.dart +++ b/packages/flutter/test/widgets/physical_model_test.dart @@ -55,17 +55,13 @@ void main() { testWidgets('PhysicalModel - creates a physical model layer when it needs compositing', (WidgetTester tester) async { debugDisableShadows = false; await tester.pumpWidget( - MediaQuery( - data: const MediaQueryData(devicePixelRatio: 1.0), - child: Directionality( - textDirection: TextDirection.ltr, - child: PhysicalModel( - shape: BoxShape.rectangle, - color: Colors.grey, - shadowColor: Colors.red, - elevation: 1.0, - child: Material(child: TextField(controller: TextEditingController())), - ), + MaterialApp( + home: PhysicalModel( + shape: BoxShape.rectangle, + color: Colors.grey, + shadowColor: Colors.red, + elevation: 1.0, + child: Material(child: TextField(controller: TextEditingController())), ), ), );