mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Rebase ios-experimental branch onto main. This will make the PRs experimenting with newer versions of Xcode (like https://github.com/flutter/flutter/pull/173123) smaller and easier to reason about. Rebases #168860 and #170274 ``` $ git rebase main -Xtheirs ``` --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Co-authored-by: Siva <a-siva@users.noreply.github.com> Co-authored-by: engine-flutter-autoroll <engine-flutter-autoroll@skia.org> Co-authored-by: Jamil Saadeh <jssaadeh@outlook.com> Co-authored-by: Dara Adedeji <76637177+SunkenInTime@users.noreply.github.com> Co-authored-by: Greg Price <gnprice@gmail.com> Co-authored-by: Ben Konyi <bkonyi@google.com> Co-authored-by: Ricardo Dalarme <ricardodalarme@outlook.com> Co-authored-by: Flutter GitHub Bot <fluttergithubbot@gmail.com> Co-authored-by: Justin McCandless <jmccandless@google.com> Co-authored-by: Alex Talebi <31685655+SalehTZ@users.noreply.github.com> Co-authored-by: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com> Co-authored-by: Mouad Debbar <mdebbar@google.com> Co-authored-by: Zuckjet <1083941774@qq.com> Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com> Co-authored-by: auto-submit[bot] <98614782+auto-submit[bot]@users.noreply.github.com> Co-authored-by: auto-submit[bot] <flutter-engprod-team@google.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: yim <ybz975218925@gmail.com> Co-authored-by: bufffun <chenmingding.cmd@alibaba-inc.com> Co-authored-by: Chinmay Garde <chinmaygarde@google.com> Co-authored-by: Hannah Jin <jhy03261997@gmail.com> Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Co-authored-by: Derek Xu <derekx@google.com> Co-authored-by: Yash Dhrangdhariya <72062416+Yash-Dhrangdhariya@users.noreply.github.com> Co-authored-by: bungeman <bungeman@chromium.org> Co-authored-by: Ahmed Mohamed Sameh <ahmedsameha1@gmail.com> Co-authored-by: John "codefu" McDole <codefu@google.com> Co-authored-by: Dmitry Grand <dmgr@google.com> Co-authored-by: Kostia Sokolovskyi <sokolovskyi.konstantin@gmail.com> Co-authored-by: Reid Baker <1063596+reidbaker@users.noreply.github.com> Co-authored-by: Matthew Kosarek <matt.kosarek@canonical.com> Co-authored-by: Jason Simmons <jason-simmons@users.noreply.github.com> Co-authored-by: Jim Graham <flar@google.com> Co-authored-by: Michael Goderbauer <goderbauer@google.com> Co-authored-by: Gray Mackall <34871572+gmackall@users.noreply.github.com> Co-authored-by: Gray Mackall <mackall@google.com> Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com> Co-authored-by: Jon Ihlas <jon.i@hotmail.fr> Co-authored-by: Micael Cid <micaelcid10@gmail.com> Co-authored-by: Alexander Aprelev <aam@google.com> Co-authored-by: hellohuanlin <41930132+hellohuanlin@users.noreply.github.com> Co-authored-by: Luke Memet <1598289+lukemmtt@users.noreply.github.com> Co-authored-by: Victoria Ashworth <15619084+vashworth@users.noreply.github.com> Co-authored-by: Mairramer <50643541+Mairramer@users.noreply.github.com> Co-authored-by: Florin Malita <fmalita@gmail.com> Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com> Co-authored-by: Salem Iranloye <127918074+salemiranloye@users.noreply.github.com> Co-authored-by: Kevin Moore <kevmoo@google.com> Co-authored-by: Sydney Bao <sydneybao@google.com> Co-authored-by: Wdestroier <Wdestroier@gmail.com> Co-authored-by: Matt Boetger <matt.boetger@gmail.com> Co-authored-by: Reid Baker <reidbaker@google.com> Co-authored-by: Victor Sanni <victorsanniay@gmail.com> Co-authored-by: Jessy Yameogo <jessy.yameogo@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: romain.gyh <11901536+romaingyh@users.noreply.github.com> Co-authored-by: Robert Ancell <robert.ancell@canonical.com> Co-authored-by: TheLastFlame <131446187+TheLastFlame@users.noreply.github.com> Co-authored-by: masato <returnymgstokh@icloud.com> Co-authored-by: Albin PK <56157868+albinpk@users.noreply.github.com> Co-authored-by: Huy <huy@nevercode.io> Co-authored-by: Matan Lurey <matanlurey@users.noreply.github.com> Co-authored-by: Azat Chorekliyev <azat24680@gmail.com> Co-authored-by: EdwynZN <edwinzn9@gmail.com> Co-authored-by: Bruno Leroux <bruno.leroux@gmail.com> Co-authored-by: Dev TtangKong <ttankkeo112@gmail.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Co-authored-by: Houssem Eddine Fadhli <houssemeddinefadhli81@gmail.com>
331 lines
12 KiB
Dart
331 lines
12 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:ui';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
test('debugChildrenHaveDuplicateKeys control test', () {
|
|
const Key key = Key('key');
|
|
final List<Widget> children = <Widget>[Container(key: key), Container(key: key)];
|
|
final Widget widget = Flex(direction: Axis.vertical, children: children);
|
|
late FlutterError error;
|
|
try {
|
|
debugChildrenHaveDuplicateKeys(widget, children);
|
|
} on FlutterError catch (e) {
|
|
error = e;
|
|
} finally {
|
|
expect(error, isNotNull);
|
|
expect(
|
|
error.toStringDeep(),
|
|
equalsIgnoringHashCodes(
|
|
'FlutterError\n'
|
|
' Duplicate keys found.\n'
|
|
' If multiple keyed widgets exist as children of another widget,\n'
|
|
' they must have unique keys.\n'
|
|
' Flex(direction: vertical, mainAxisAlignment: start,\n'
|
|
' crossAxisAlignment: center) has multiple children with key\n'
|
|
" [<'key'>].\n",
|
|
),
|
|
);
|
|
}
|
|
});
|
|
|
|
test('debugItemsHaveDuplicateKeys control test', () {
|
|
const Key key = Key('key');
|
|
final List<Widget> items = <Widget>[Container(key: key), Container(key: key)];
|
|
late FlutterError error;
|
|
try {
|
|
debugItemsHaveDuplicateKeys(items);
|
|
} on FlutterError catch (e) {
|
|
error = e;
|
|
} finally {
|
|
expect(error, isNotNull);
|
|
expect(
|
|
error.toStringDeep(),
|
|
equalsIgnoringHashCodes(
|
|
'FlutterError\n'
|
|
" Duplicate key found: [<'key'>].\n",
|
|
),
|
|
);
|
|
}
|
|
});
|
|
|
|
testWidgets('debugCheckHasTable control test', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
Builder(
|
|
builder: (BuildContext context) {
|
|
late FlutterError error;
|
|
try {
|
|
debugCheckHasTable(context);
|
|
} on FlutterError catch (e) {
|
|
error = e;
|
|
} finally {
|
|
expect(error, isNotNull);
|
|
expect(error.diagnostics.length, 4);
|
|
expect(error.diagnostics[2], isA<DiagnosticsProperty<Element>>());
|
|
expect(
|
|
error.toStringDeep(),
|
|
startsWith(
|
|
'FlutterError\n'
|
|
' No Table widget found.\n'
|
|
' Builder widgets require a Table widget ancestor.\n'
|
|
' The specific widget that could not find a Table ancestor was:\n'
|
|
' Builder\n'
|
|
' The ownership chain for the affected widget is: "Builder ←', // End of ownership chain omitted, not relevant for test.
|
|
),
|
|
);
|
|
}
|
|
return Container();
|
|
},
|
|
),
|
|
);
|
|
});
|
|
|
|
testWidgets('debugCheckHasMediaQuery control test', (WidgetTester tester) async {
|
|
// Cannot use tester.pumpWidget here because it wraps the widget in a View,
|
|
// which introduces a MediaQuery ancestor.
|
|
await tester.pumpWidget(
|
|
wrapWithView: false,
|
|
Builder(
|
|
builder: (BuildContext context) {
|
|
late FlutterError error;
|
|
try {
|
|
debugCheckHasMediaQuery(context);
|
|
} on FlutterError catch (e) {
|
|
error = e;
|
|
} finally {
|
|
expect(error, isNotNull);
|
|
expect(error.diagnostics.length, 5);
|
|
expect(error.diagnostics[2], isA<DiagnosticsProperty<Element>>());
|
|
expect(error.diagnostics.last.level, DiagnosticLevel.hint);
|
|
expect(
|
|
error.diagnostics.last.toStringDeep(),
|
|
equalsIgnoringHashCodes(
|
|
'No MediaQuery ancestor could be found starting from the context\n'
|
|
'that was passed to MediaQuery.of(). This can happen because the\n'
|
|
'context used is not a descendant of a View widget, which\n'
|
|
'introduces a MediaQuery.\n',
|
|
),
|
|
);
|
|
expect(
|
|
error.toStringDeep(),
|
|
startsWith(
|
|
'FlutterError\n'
|
|
' No MediaQuery widget ancestor found.\n'
|
|
' Builder widgets require a MediaQuery widget ancestor.\n'
|
|
' The specific widget that could not find a MediaQuery ancestor\n'
|
|
' was:\n'
|
|
' Builder\n'
|
|
' The ownership chain for the affected widget is: "Builder ←', // Full chain omitted, not relevant for test.
|
|
),
|
|
);
|
|
expect(
|
|
error.toStringDeep(),
|
|
endsWith(
|
|
'[root]"\n' // End of ownership chain.
|
|
' No MediaQuery ancestor could be found starting from the context\n'
|
|
' that was passed to MediaQuery.of(). This can happen because the\n'
|
|
' context used is not a descendant of a View widget, which\n'
|
|
' introduces a MediaQuery.\n',
|
|
),
|
|
);
|
|
}
|
|
return View(view: tester.view, child: const SizedBox());
|
|
},
|
|
),
|
|
);
|
|
});
|
|
|
|
test('debugWidgetBuilderValue control test', () {
|
|
final Widget widget = Container();
|
|
FlutterError? error;
|
|
try {
|
|
debugWidgetBuilderValue(widget, null);
|
|
} on FlutterError catch (e) {
|
|
error = e;
|
|
} finally {
|
|
expect(error, isNotNull);
|
|
expect(error!.diagnostics.length, 4);
|
|
expect(error.diagnostics[1], isA<DiagnosticsProperty<Widget>>());
|
|
expect(error.diagnostics[1].style, DiagnosticsTreeStyle.errorProperty);
|
|
expect(
|
|
error.diagnostics[1].toStringDeep(),
|
|
equalsIgnoringHashCodes(
|
|
'The offending widget is:\n'
|
|
' Container\n',
|
|
),
|
|
);
|
|
expect(error.diagnostics[2].level, DiagnosticLevel.info);
|
|
expect(error.diagnostics[3].level, DiagnosticLevel.hint);
|
|
expect(
|
|
error.diagnostics[3].toStringDeep(),
|
|
equalsIgnoringHashCodes(
|
|
'To return an empty space that causes the building widget to fill\n'
|
|
'available room, return "Container()". To return an empty space\n'
|
|
'that takes as little room as possible, return "Container(width:\n'
|
|
'0.0, height: 0.0)".\n',
|
|
),
|
|
);
|
|
expect(
|
|
error.toStringDeep(),
|
|
equalsIgnoringHashCodes(
|
|
'FlutterError\n'
|
|
' A build function returned null.\n'
|
|
' The offending widget is:\n'
|
|
' Container\n'
|
|
' Build functions must never return null.\n'
|
|
' To return an empty space that causes the building widget to fill\n'
|
|
' available room, return "Container()". To return an empty space\n'
|
|
' that takes as little room as possible, return "Container(width:\n'
|
|
' 0.0, height: 0.0)".\n',
|
|
),
|
|
);
|
|
error = null;
|
|
}
|
|
try {
|
|
debugWidgetBuilderValue(widget, widget);
|
|
} on FlutterError catch (e) {
|
|
error = e;
|
|
} finally {
|
|
expect(error, isNotNull);
|
|
expect(error!.diagnostics.length, 3);
|
|
expect(error.diagnostics[1], isA<DiagnosticsProperty<Widget>>());
|
|
expect(error.diagnostics[1].style, DiagnosticsTreeStyle.errorProperty);
|
|
expect(
|
|
error.diagnostics[1].toStringDeep(),
|
|
equalsIgnoringHashCodes(
|
|
'The offending widget is:\n'
|
|
' Container\n',
|
|
),
|
|
);
|
|
expect(
|
|
error.toStringDeep(),
|
|
equalsIgnoringHashCodes(
|
|
'FlutterError\n'
|
|
' A build function returned context.widget.\n'
|
|
' The offending widget is:\n'
|
|
' Container\n'
|
|
" Build functions must never return their BuildContext parameter's\n"
|
|
' widget or a child that contains "context.widget". Doing so\n'
|
|
' introduces a loop in the widget tree that can cause the app to\n'
|
|
' crash.\n',
|
|
),
|
|
);
|
|
}
|
|
});
|
|
|
|
testWidgets('debugCheckHasWidgetsLocalizations throws', (WidgetTester tester) async {
|
|
final GlobalKey noLocalizationsAvailable = GlobalKey();
|
|
final GlobalKey localizationsAvailable = GlobalKey();
|
|
|
|
await tester.pumpWidget(
|
|
Container(
|
|
key: noLocalizationsAvailable,
|
|
child: WidgetsApp(
|
|
builder: (BuildContext context, Widget? child) {
|
|
return Container(key: localizationsAvailable);
|
|
},
|
|
color: const Color(0xFF4CAF50),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(
|
|
() => debugCheckHasWidgetsLocalizations(noLocalizationsAvailable.currentContext!),
|
|
throwsA(
|
|
isAssertionError.having(
|
|
(AssertionError e) => e.message,
|
|
'message',
|
|
contains('No WidgetsLocalizations found'),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(debugCheckHasWidgetsLocalizations(localizationsAvailable.currentContext!), isTrue);
|
|
});
|
|
|
|
test('debugAssertAllWidgetVarsUnset', () {
|
|
debugHighlightDeprecatedWidgets = true;
|
|
late FlutterError error;
|
|
try {
|
|
debugAssertAllWidgetVarsUnset(
|
|
'The value of a widget debug variable was changed by the test.',
|
|
);
|
|
} on FlutterError catch (e) {
|
|
error = e;
|
|
} finally {
|
|
expect(error, isNotNull);
|
|
expect(error.diagnostics.length, 1);
|
|
expect(
|
|
error.toStringDeep(),
|
|
'FlutterError\n'
|
|
' The value of a widget debug variable was changed by the test.\n',
|
|
);
|
|
}
|
|
debugHighlightDeprecatedWidgets = false;
|
|
});
|
|
|
|
testWidgets('debugCreator of layers should not be null', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: Material(
|
|
child: Stack(
|
|
children: <Widget>[
|
|
const ColorFiltered(
|
|
colorFilter: ColorFilter.mode(Color(0xFFFF0000), BlendMode.color),
|
|
child: Placeholder(),
|
|
),
|
|
const Opacity(opacity: 0.9, child: Placeholder()),
|
|
ImageFiltered(
|
|
imageFilter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
|
|
child: const Placeholder(),
|
|
),
|
|
BackdropFilter(
|
|
filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
|
|
child: const Placeholder(),
|
|
),
|
|
ShaderMask(
|
|
shaderCallback: (Rect bounds) => const RadialGradient(
|
|
radius: 0.05,
|
|
colors: <Color>[Color(0xFFFF0000), Color(0xFF00FF00)],
|
|
tileMode: TileMode.mirror,
|
|
).createShader(bounds),
|
|
child: const Placeholder(),
|
|
),
|
|
CompositedTransformFollower(link: LayerLink()),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
RenderObject renderObject;
|
|
|
|
renderObject = tester.firstRenderObject(find.byType(Opacity));
|
|
expect(renderObject.debugLayer?.debugCreator, isNotNull);
|
|
|
|
renderObject = tester.firstRenderObject(find.byType(ColorFiltered));
|
|
expect(renderObject.debugLayer?.debugCreator, isNotNull);
|
|
|
|
renderObject = tester.firstRenderObject(find.byType(ImageFiltered));
|
|
expect(renderObject.debugLayer?.debugCreator, isNotNull);
|
|
|
|
renderObject = tester.firstRenderObject(find.byType(BackdropFilter));
|
|
expect(renderObject.debugLayer?.debugCreator, isNotNull);
|
|
|
|
renderObject = tester.firstRenderObject(find.byType(ShaderMask));
|
|
expect(renderObject.debugLayer?.debugCreator, isNotNull);
|
|
|
|
renderObject = tester.firstRenderObject(find.byType(CompositedTransformFollower));
|
|
expect(renderObject.debugLayer?.debugCreator, isNotNull);
|
|
});
|
|
}
|