mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Step 1 of 3: Add opt-in for debugCheckHasMaterialLocalizations assertion on TextField (#56090)
This commit is contained in:
parent
ae46203862
commit
c733864aff
@ -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<String> 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<TextField> 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 &&
|
||||
|
||||
@ -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())),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user