Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -4,23 +4,17 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_api_samples/widgets/text_magnifier/text_magnifier.0.dart'
|
||||
as example;
|
||||
import 'package:flutter_api_samples/widgets/text_magnifier/text_magnifier.0.dart' as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
List<TextSelectionPoint> _globalize(
|
||||
Iterable<TextSelectionPoint> points, RenderBox box) {
|
||||
List<TextSelectionPoint> _globalize(Iterable<TextSelectionPoint> points, RenderBox box) {
|
||||
return points.map<TextSelectionPoint>((TextSelectionPoint point) {
|
||||
return TextSelectionPoint(
|
||||
box.localToGlobal(point.point),
|
||||
point.direction,
|
||||
);
|
||||
return TextSelectionPoint(box.localToGlobal(point.point), point.direction);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
RenderEditable _findRenderEditable<T extends State<StatefulWidget>>(WidgetTester tester) {
|
||||
return (tester.state(find.byType(TextField))
|
||||
as TextSelectionGestureDetectorBuilderDelegate)
|
||||
return (tester.state(find.byType(TextField)) as TextSelectionGestureDetectorBuilderDelegate)
|
||||
.editableTextKey
|
||||
.currentState!
|
||||
.renderEditable;
|
||||
@@ -29,15 +23,14 @@ RenderEditable _findRenderEditable<T extends State<StatefulWidget>>(WidgetTester
|
||||
Offset _textOffsetToPosition<T extends State<StatefulWidget>>(WidgetTester tester, int offset) {
|
||||
final RenderEditable renderEditable = _findRenderEditable(tester);
|
||||
|
||||
final List<TextSelectionPoint> endpoints = renderEditable
|
||||
.getEndpointsForSelection(
|
||||
TextSelection.collapsed(offset: offset),
|
||||
)
|
||||
.map<TextSelectionPoint>((TextSelectionPoint point) => TextSelectionPoint(
|
||||
renderEditable.localToGlobal(point.point),
|
||||
point.direction,
|
||||
))
|
||||
.toList();
|
||||
final List<TextSelectionPoint> endpoints =
|
||||
renderEditable
|
||||
.getEndpointsForSelection(TextSelection.collapsed(offset: offset))
|
||||
.map<TextSelectionPoint>(
|
||||
(TextSelectionPoint point) =>
|
||||
TextSelectionPoint(renderEditable.localToGlobal(point.point), point.direction),
|
||||
)
|
||||
.toList();
|
||||
|
||||
return endpoints[0].point + const Offset(0.0, -2.0);
|
||||
}
|
||||
@@ -60,9 +53,8 @@ void main() {
|
||||
await testGesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final TextEditingController controller = tester
|
||||
.firstWidget<TextField>(find.byType(TextField))
|
||||
.controller!;
|
||||
final TextEditingController controller =
|
||||
tester.firstWidget<TextField>(find.byType(TextField)).controller!;
|
||||
|
||||
final TextSelection selection = controller.selection;
|
||||
final RenderEditable renderEditable = _findRenderEditable(tester);
|
||||
@@ -75,40 +67,40 @@ void main() {
|
||||
|
||||
final TestGesture gesture = await tester.startGesture(handlePos);
|
||||
|
||||
await gesture.moveTo(
|
||||
_textOffsetToPosition(
|
||||
tester,
|
||||
defaultText.length - 2,
|
||||
),
|
||||
);
|
||||
await gesture.moveTo(_textOffsetToPosition(tester, defaultText.length - 2));
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
testWidgets('should show custom magnifier on drag', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const example.TextMagnifierExampleApp(text: defaultText));
|
||||
testWidgets(
|
||||
'should show custom magnifier on drag',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const example.TextMagnifierExampleApp(text: defaultText));
|
||||
|
||||
await showMagnifier(tester, defaultText.indexOf('e'));
|
||||
expect(find.byType(example.CustomMagnifier), findsOneWidget);
|
||||
await showMagnifier(tester, defaultText.indexOf('e'));
|
||||
expect(find.byType(example.CustomMagnifier), findsOneWidget);
|
||||
|
||||
await expectLater(
|
||||
find.byType(example.TextMagnifierExampleApp),
|
||||
matchesGoldenFile('text_magnifier.0_test.png'),
|
||||
);
|
||||
},
|
||||
variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.android }),
|
||||
await expectLater(
|
||||
find.byType(example.TextMagnifierExampleApp),
|
||||
matchesGoldenFile('text_magnifier.0_test.png'),
|
||||
);
|
||||
},
|
||||
variant: const TargetPlatformVariant(<TargetPlatform>{
|
||||
TargetPlatform.iOS,
|
||||
TargetPlatform.android,
|
||||
}),
|
||||
skip: true, // This image is flaky. https://github.com/flutter/flutter/issues/144350
|
||||
);
|
||||
|
||||
|
||||
testWidgets('should show custom magnifier in RTL', (WidgetTester tester) async {
|
||||
const String text = 'أثارت زر';
|
||||
const String textToTapOn = 'ت';
|
||||
|
||||
await tester.pumpWidget(const example.TextMagnifierExampleApp(textDirection: TextDirection.rtl, text: text));
|
||||
await tester.pumpWidget(
|
||||
const example.TextMagnifierExampleApp(textDirection: TextDirection.rtl, text: text),
|
||||
);
|
||||
|
||||
await showMagnifier(tester, text.indexOf(textToTapOn));
|
||||
|
||||
expect(find.byType(example.CustomMagnifier), findsOneWidget);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user