Michael Goderbauer 5491c8c146
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>
2024-12-19 20:06:21 +00:00

75 lines
2.5 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 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
/// A mock class to control the return result of Live Text input functions.
class LiveTextInputTester {
LiveTextInputTester() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
_handler,
);
}
bool mockLiveTextInputEnabled = false;
Future<Object?> _handler(MethodCall methodCall) async {
// Need to set Clipboard.hasStrings method handler because when showing the tool bar,
// the Clipboard.hasStrings will also be invoked. If this isn't handled,
// an exception will be thrown.
if (methodCall.method == 'Clipboard.hasStrings') {
return <String, bool>{'value': true};
}
if (methodCall.method == 'LiveText.isLiveTextInputAvailable') {
return mockLiveTextInputEnabled;
}
return false;
}
void dispose() {
assert(
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.checkMockMessageHandler(
SystemChannels.platform.name,
_handler,
),
);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
);
}
}
/// A function to find the live text button.
///
/// LiveText button is displayed either using a custom painter,
/// a Text with an empty label, or a Text with the 'Scan text' label.
Finder findLiveTextButton() {
final bool isMobile =
defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.fuchsia ||
defaultTargetPlatform == TargetPlatform.iOS;
if (isMobile) {
return find.byWidgetPredicate((Widget widget) {
return (widget is CustomPaint &&
'${widget.painter?.runtimeType}' == '_LiveTextIconPainter') ||
(widget is Text &&
widget.data == 'Scan text'); // Android and Fuchsia when inside a MaterialApp.
});
}
if (defaultTargetPlatform == TargetPlatform.macOS) {
return find.ancestor(
of: find.text(''),
matching: find.byType(CupertinoDesktopTextSelectionToolbarButton),
);
}
return find.byWidgetPredicate((Widget widget) {
return widget is Text && (widget.data == '' || widget.data == 'Scan text');
});
}