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
@@ -44,13 +44,11 @@ class PathUrlStrategy extends ui_web.HashUrlStrategy {
|
||||
///
|
||||
/// The [ui_web.PlatformLocation] parameter is useful for testing to mock out browser
|
||||
/// interactions.
|
||||
PathUrlStrategy([
|
||||
super.platformLocation,
|
||||
this.includeHash = false,
|
||||
]) : _platformLocation = platformLocation,
|
||||
_basePath = stripTrailingSlash(extractPathname(checkBaseHref(
|
||||
platformLocation.getBaseHref(),
|
||||
)));
|
||||
PathUrlStrategy([super.platformLocation, this.includeHash = false])
|
||||
: _platformLocation = platformLocation,
|
||||
_basePath = stripTrailingSlash(
|
||||
extractPathname(checkBaseHref(platformLocation.getBaseHref())),
|
||||
);
|
||||
|
||||
final ui_web.PlatformLocation _platformLocation;
|
||||
final String _basePath;
|
||||
|
||||
@@ -129,5 +129,5 @@ class PathUrlStrategy extends HashUrlStrategy {
|
||||
///
|
||||
/// The [PlatformLocation] parameter is useful for testing to mock out browser
|
||||
/// integrations.
|
||||
const PathUrlStrategy([PlatformLocation? _, bool __ = false,]);
|
||||
const PathUrlStrategy([PlatformLocation? _, bool __ = false]);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class PluginEventChannel<T> {
|
||||
/// and providing a getter would require making this class non-const.
|
||||
@Deprecated(
|
||||
'Replace calls to the "controller" setter with calls to the "setController" method. '
|
||||
'This feature was deprecated after v1.23.0-7.0.pre.'
|
||||
'This feature was deprecated after v1.23.0-7.0.pre.',
|
||||
)
|
||||
// ignore: avoid_setters_without_getters
|
||||
set controller(StreamController<T> controller) {
|
||||
@@ -98,12 +98,7 @@ class PluginEventChannel<T> {
|
||||
}
|
||||
|
||||
class _EventChannelHandler<T> {
|
||||
_EventChannelHandler(
|
||||
this.name,
|
||||
this.codec,
|
||||
this.controller,
|
||||
this.messenger,
|
||||
);
|
||||
_EventChannelHandler(this.name, this.codec, this.controller, this.messenger);
|
||||
|
||||
final String name;
|
||||
final MethodCodec codec;
|
||||
@@ -128,20 +123,20 @@ class _EventChannelHandler<T> {
|
||||
Future<ByteData> _listen() async {
|
||||
// Cancel any existing subscription.
|
||||
await subscription?.cancel();
|
||||
subscription = controller.stream.listen((dynamic event) {
|
||||
messenger.send(name, codec.encodeSuccessEnvelope(event));
|
||||
}, onError: (dynamic error) {
|
||||
messenger.send(name, codec.encodeErrorEnvelope(code: 'error', message: '$error'));
|
||||
});
|
||||
subscription = controller.stream.listen(
|
||||
(dynamic event) {
|
||||
messenger.send(name, codec.encodeSuccessEnvelope(event));
|
||||
},
|
||||
onError: (dynamic error) {
|
||||
messenger.send(name, codec.encodeErrorEnvelope(code: 'error', message: '$error'));
|
||||
},
|
||||
);
|
||||
return codec.encodeSuccessEnvelope(null);
|
||||
}
|
||||
|
||||
Future<ByteData> _cancel() async {
|
||||
if (subscription == null) {
|
||||
return codec.encodeErrorEnvelope(
|
||||
code: 'error',
|
||||
message: 'No active subscription to cancel.',
|
||||
);
|
||||
return codec.encodeErrorEnvelope(code: 'error', message: 'No active subscription to cancel.');
|
||||
}
|
||||
await subscription!.cancel();
|
||||
subscription = null;
|
||||
|
||||
@@ -54,7 +54,7 @@ class Registrar extends BinaryMessenger {
|
||||
Registrar([
|
||||
@Deprecated(
|
||||
'This argument is ignored. '
|
||||
'This feature was deprecated after v1.24.0-7.0.pre.'
|
||||
'This feature was deprecated after v1.24.0-7.0.pre.',
|
||||
)
|
||||
BinaryMessenger? binaryMessenger,
|
||||
]);
|
||||
@@ -81,7 +81,7 @@ class Registrar extends BinaryMessenger {
|
||||
/// This method has been replaced with the more clearly-named [handleFrameworkMessage].
|
||||
@Deprecated(
|
||||
'Use handleFrameworkMessage instead. '
|
||||
'This feature was deprecated after v1.24.0-7.0.pre.'
|
||||
'This feature was deprecated after v1.24.0-7.0.pre.',
|
||||
)
|
||||
@override
|
||||
Future<void> handlePlatformMessage(
|
||||
@@ -125,12 +125,14 @@ class Registrar extends BinaryMessenger {
|
||||
response = await handler(data);
|
||||
}
|
||||
} catch (exception, stack) {
|
||||
FlutterError.reportError(FlutterErrorDetails(
|
||||
exception: exception,
|
||||
stack: stack,
|
||||
library: 'flutter web plugins',
|
||||
context: ErrorDescription('during a framework-to-plugin message'),
|
||||
));
|
||||
FlutterError.reportError(
|
||||
FlutterErrorDetails(
|
||||
exception: exception,
|
||||
stack: stack,
|
||||
library: 'flutter web plugins',
|
||||
context: ErrorDescription('during a framework-to-plugin message'),
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
if (callback != null) {
|
||||
callback(response);
|
||||
@@ -141,7 +143,7 @@ class Registrar extends BinaryMessenger {
|
||||
/// Returns `this`.
|
||||
@Deprecated(
|
||||
'This property is redundant. It returns the object on which it is called. '
|
||||
'This feature was deprecated after v1.24.0-7.0.pre.'
|
||||
'This feature was deprecated after v1.24.0-7.0.pre.',
|
||||
)
|
||||
BinaryMessenger get messenger => this;
|
||||
|
||||
@@ -155,12 +157,14 @@ class Registrar extends BinaryMessenger {
|
||||
try {
|
||||
completer.complete(reply);
|
||||
} catch (exception, stack) {
|
||||
FlutterError.reportError(FlutterErrorDetails(
|
||||
exception: exception,
|
||||
stack: stack,
|
||||
library: 'flutter web plugins',
|
||||
context: ErrorDescription('during a plugin-to-framework message'),
|
||||
));
|
||||
FlutterError.reportError(
|
||||
FlutterErrorDetails(
|
||||
exception: exception,
|
||||
stack: stack,
|
||||
library: 'flutter web plugins',
|
||||
context: ErrorDescription('during a plugin-to-framework message'),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
return completer.future;
|
||||
@@ -180,7 +184,7 @@ class Registrar extends BinaryMessenger {
|
||||
/// as part of a simplification of the web plugins API.
|
||||
@Deprecated(
|
||||
'Use Registrar instead. '
|
||||
'This feature was deprecated after v1.26.0-18.0.pre.'
|
||||
'This feature was deprecated after v1.26.0-18.0.pre.',
|
||||
)
|
||||
class PluginRegistry extends Registrar {
|
||||
/// Creates a [Registrar].
|
||||
@@ -188,12 +192,12 @@ class PluginRegistry extends Registrar {
|
||||
/// The argument is ignored.
|
||||
@Deprecated(
|
||||
'Use Registrar instead. '
|
||||
'This feature was deprecated after v1.26.0-18.0.pre.'
|
||||
'This feature was deprecated after v1.26.0-18.0.pre.',
|
||||
)
|
||||
PluginRegistry([
|
||||
@Deprecated(
|
||||
'This argument is ignored. '
|
||||
'This feature was deprecated after v1.26.0-18.0.pre.'
|
||||
'This feature was deprecated after v1.26.0-18.0.pre.',
|
||||
)
|
||||
BinaryMessenger? binaryMessenger,
|
||||
]) : super();
|
||||
@@ -201,7 +205,7 @@ class PluginRegistry extends Registrar {
|
||||
/// Returns `this`. The argument is ignored.
|
||||
@Deprecated(
|
||||
'This method is redundant. It returns the object on which it is called. '
|
||||
'This feature was deprecated after v1.26.0-18.0.pre.'
|
||||
'This feature was deprecated after v1.26.0-18.0.pre.',
|
||||
)
|
||||
Registrar registrarFor(Type key) => this;
|
||||
}
|
||||
@@ -212,13 +216,13 @@ final Registrar webPluginRegistrar = PluginRegistry();
|
||||
/// A deprecated alias for [webPluginRegistrar].
|
||||
@Deprecated(
|
||||
'Use webPluginRegistrar instead. '
|
||||
'This feature was deprecated after v1.24.0-7.0.pre.'
|
||||
'This feature was deprecated after v1.24.0-7.0.pre.',
|
||||
)
|
||||
PluginRegistry get webPluginRegistry => webPluginRegistrar as PluginRegistry;
|
||||
|
||||
/// A deprecated alias for [webPluginRegistrar].
|
||||
@Deprecated(
|
||||
'Use webPluginRegistrar instead. '
|
||||
'This feature was deprecated after v1.24.0-7.0.pre.'
|
||||
'This feature was deprecated after v1.24.0-7.0.pre.',
|
||||
)
|
||||
BinaryMessenger get pluginBinaryMessenger => webPluginRegistrar;
|
||||
|
||||
@@ -26,34 +26,19 @@ void main() {
|
||||
});
|
||||
|
||||
test('validates base href', () {
|
||||
expect(
|
||||
() => PathUrlStrategy(location),
|
||||
returnsNormally,
|
||||
);
|
||||
expect(() => PathUrlStrategy(location), returnsNormally);
|
||||
|
||||
location.baseHref = '/foo/';
|
||||
expect(
|
||||
() => PathUrlStrategy(location),
|
||||
returnsNormally,
|
||||
);
|
||||
expect(() => PathUrlStrategy(location), returnsNormally);
|
||||
|
||||
location.baseHref = '';
|
||||
expect(
|
||||
() => PathUrlStrategy(location),
|
||||
throwsException,
|
||||
);
|
||||
expect(() => PathUrlStrategy(location), throwsException);
|
||||
|
||||
location.baseHref = 'foo';
|
||||
expect(
|
||||
() => PathUrlStrategy(location),
|
||||
throwsException,
|
||||
);
|
||||
expect(() => PathUrlStrategy(location), throwsException);
|
||||
|
||||
location.baseHref = '/foo';
|
||||
expect(
|
||||
() => PathUrlStrategy(location),
|
||||
throwsException,
|
||||
);
|
||||
expect(() => PathUrlStrategy(location), throwsException);
|
||||
});
|
||||
|
||||
test('leading slash is always prepended', () {
|
||||
@@ -80,20 +65,23 @@ void main() {
|
||||
expect(strategy.getPath(), '/bar');
|
||||
});
|
||||
|
||||
test('gets path correctly in the presence of query params and omits fragment if no flag specified', () {
|
||||
location.baseHref = 'https://example.com/foo/';
|
||||
location.pathname = '/foo/bar';
|
||||
final PathUrlStrategy strategy = PathUrlStrategy(location);
|
||||
test(
|
||||
'gets path correctly in the presence of query params and omits fragment if no flag specified',
|
||||
() {
|
||||
location.baseHref = 'https://example.com/foo/';
|
||||
location.pathname = '/foo/bar';
|
||||
final PathUrlStrategy strategy = PathUrlStrategy(location);
|
||||
|
||||
location.search = '?q=1';
|
||||
expect(strategy.getPath(), '/bar?q=1');
|
||||
location.search = '?q=1';
|
||||
expect(strategy.getPath(), '/bar?q=1');
|
||||
|
||||
location.search = '?q=1&t=r';
|
||||
expect(strategy.getPath(), '/bar?q=1&t=r');
|
||||
location.search = '?q=1&t=r';
|
||||
expect(strategy.getPath(), '/bar?q=1&t=r');
|
||||
|
||||
location.hash = '#fragment=1';
|
||||
expect(strategy.getPath(), '/bar?q=1&t=r');
|
||||
});
|
||||
location.hash = '#fragment=1';
|
||||
expect(strategy.getPath(), '/bar?q=1&t=r');
|
||||
},
|
||||
);
|
||||
|
||||
test('gets path correctly in the presence of query params and fragment', () {
|
||||
location.baseHref = 'https://example.com/foo/';
|
||||
|
||||
@@ -24,14 +24,12 @@ void main() {
|
||||
|
||||
test('can send events to an $EventChannel (deprecated API)', () async {
|
||||
const EventChannel listeningChannel = EventChannel('test');
|
||||
const PluginEventChannel<String> sendingChannel =
|
||||
PluginEventChannel<String>('test');
|
||||
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test');
|
||||
|
||||
final StreamController<String> controller = StreamController<String>();
|
||||
sendingChannel.setController(controller);
|
||||
|
||||
expect(listeningChannel.receiveBroadcastStream(),
|
||||
emitsInOrder(<String>['hello', 'world']));
|
||||
expect(listeningChannel.receiveBroadcastStream(), emitsInOrder(<String>['hello', 'world']));
|
||||
|
||||
controller.add('hello');
|
||||
controller.add('world');
|
||||
@@ -40,14 +38,12 @@ void main() {
|
||||
|
||||
test('can send events to an $EventChannel', () async {
|
||||
const EventChannel listeningChannel = EventChannel('test');
|
||||
const PluginEventChannel<String> sendingChannel =
|
||||
PluginEventChannel<String>('test');
|
||||
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test');
|
||||
|
||||
final StreamController<String> controller = StreamController<String>();
|
||||
sendingChannel.setController(controller);
|
||||
|
||||
expect(listeningChannel.receiveBroadcastStream(),
|
||||
emitsInOrder(<String>['hello', 'world']));
|
||||
expect(listeningChannel.receiveBroadcastStream(), emitsInOrder(<String>['hello', 'world']));
|
||||
|
||||
controller.add('hello');
|
||||
controller.add('world');
|
||||
@@ -56,16 +52,17 @@ void main() {
|
||||
|
||||
test('can send errors to an $EventChannel (deprecated API)', () async {
|
||||
const EventChannel listeningChannel = EventChannel('test2');
|
||||
const PluginEventChannel<String> sendingChannel =
|
||||
PluginEventChannel<String>('test2');
|
||||
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test2');
|
||||
|
||||
final StreamController<String> controller = StreamController<String>();
|
||||
sendingChannel.setController(controller);
|
||||
|
||||
expect(
|
||||
listeningChannel.receiveBroadcastStream(),
|
||||
emitsError(predicate<dynamic>((dynamic e) =>
|
||||
e is PlatformException && e.message == 'Test error')));
|
||||
listeningChannel.receiveBroadcastStream(),
|
||||
emitsError(
|
||||
predicate<dynamic>((dynamic e) => e is PlatformException && e.message == 'Test error'),
|
||||
),
|
||||
);
|
||||
|
||||
controller.addError('Test error');
|
||||
await controller.close();
|
||||
@@ -73,16 +70,17 @@ void main() {
|
||||
|
||||
test('can send errors to an $EventChannel', () async {
|
||||
const EventChannel listeningChannel = EventChannel('test2');
|
||||
const PluginEventChannel<String> sendingChannel =
|
||||
PluginEventChannel<String>('test2');
|
||||
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test2');
|
||||
|
||||
final StreamController<String> controller = StreamController<String>();
|
||||
sendingChannel.setController(controller);
|
||||
|
||||
expect(
|
||||
listeningChannel.receiveBroadcastStream(),
|
||||
emitsError(predicate<dynamic>((dynamic e) =>
|
||||
e is PlatformException && e.message == 'Test error')));
|
||||
listeningChannel.receiveBroadcastStream(),
|
||||
emitsError(
|
||||
predicate<dynamic>((dynamic e) => e is PlatformException && e.message == 'Test error'),
|
||||
),
|
||||
);
|
||||
|
||||
controller.addError('Test error');
|
||||
await controller.close();
|
||||
@@ -90,15 +88,14 @@ void main() {
|
||||
|
||||
test('receives a listen event (deprecated API)', () async {
|
||||
const EventChannel listeningChannel = EventChannel('test3');
|
||||
const PluginEventChannel<String> sendingChannel =
|
||||
PluginEventChannel<String>('test3');
|
||||
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test3');
|
||||
|
||||
final StreamController<String> controller = StreamController<String>(
|
||||
onListen: expectAsync0<void>(() {}));
|
||||
onListen: expectAsync0<void>(() {}),
|
||||
);
|
||||
sendingChannel.setController(controller);
|
||||
|
||||
expect(listeningChannel.receiveBroadcastStream(),
|
||||
emitsInOrder(<String>['hello']));
|
||||
expect(listeningChannel.receiveBroadcastStream(), emitsInOrder(<String>['hello']));
|
||||
|
||||
controller.add('hello');
|
||||
await controller.close();
|
||||
@@ -106,15 +103,14 @@ void main() {
|
||||
|
||||
test('receives a listen event', () async {
|
||||
const EventChannel listeningChannel = EventChannel('test3');
|
||||
const PluginEventChannel<String> sendingChannel =
|
||||
PluginEventChannel<String>('test3');
|
||||
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test3');
|
||||
|
||||
final StreamController<String> controller = StreamController<String>(
|
||||
onListen: expectAsync0<void>(() {}));
|
||||
onListen: expectAsync0<void>(() {}),
|
||||
);
|
||||
sendingChannel.setController(controller);
|
||||
|
||||
expect(listeningChannel.receiveBroadcastStream(),
|
||||
emitsInOrder(<String>['hello']));
|
||||
expect(listeningChannel.receiveBroadcastStream(), emitsInOrder(<String>['hello']));
|
||||
|
||||
controller.add('hello');
|
||||
await controller.close();
|
||||
@@ -122,42 +118,42 @@ void main() {
|
||||
|
||||
test('receives a cancel event (deprecated API)', () async {
|
||||
const EventChannel listeningChannel = EventChannel('test4');
|
||||
const PluginEventChannel<String> sendingChannel =
|
||||
PluginEventChannel<String>('test4');
|
||||
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test4');
|
||||
|
||||
final StreamController<String> controller =
|
||||
StreamController<String>(onCancel: expectAsync0<void>(() {}));
|
||||
final StreamController<String> controller = StreamController<String>(
|
||||
onCancel: expectAsync0<void>(() {}),
|
||||
);
|
||||
sendingChannel.setController(controller);
|
||||
|
||||
final Stream<dynamic> eventStream =
|
||||
listeningChannel.receiveBroadcastStream();
|
||||
final Stream<dynamic> eventStream = listeningChannel.receiveBroadcastStream();
|
||||
late StreamSubscription<dynamic> subscription;
|
||||
subscription =
|
||||
eventStream.listen(expectAsync1<void, dynamic>((dynamic x) {
|
||||
expect(x, equals('hello'));
|
||||
subscription.cancel();
|
||||
}));
|
||||
subscription = eventStream.listen(
|
||||
expectAsync1<void, dynamic>((dynamic x) {
|
||||
expect(x, equals('hello'));
|
||||
subscription.cancel();
|
||||
}),
|
||||
);
|
||||
|
||||
controller.add('hello');
|
||||
});
|
||||
|
||||
test('receives a cancel event', () async {
|
||||
const EventChannel listeningChannel = EventChannel('test4');
|
||||
const PluginEventChannel<String> sendingChannel =
|
||||
PluginEventChannel<String>('test4');
|
||||
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test4');
|
||||
|
||||
final StreamController<String> controller =
|
||||
StreamController<String>(onCancel: expectAsync0<void>(() {}));
|
||||
final StreamController<String> controller = StreamController<String>(
|
||||
onCancel: expectAsync0<void>(() {}),
|
||||
);
|
||||
sendingChannel.setController(controller);
|
||||
|
||||
final Stream<dynamic> eventStream =
|
||||
listeningChannel.receiveBroadcastStream();
|
||||
final Stream<dynamic> eventStream = listeningChannel.receiveBroadcastStream();
|
||||
late StreamSubscription<dynamic> subscription;
|
||||
subscription =
|
||||
eventStream.listen(expectAsync1<void, dynamic>((dynamic x) {
|
||||
expect(x, equals('hello'));
|
||||
subscription.cancel();
|
||||
}));
|
||||
subscription = eventStream.listen(
|
||||
expectAsync1<void, dynamic>((dynamic x) {
|
||||
expect(x, equals('hello'));
|
||||
subscription.cancel();
|
||||
}),
|
||||
);
|
||||
|
||||
controller.add('hello');
|
||||
});
|
||||
|
||||
@@ -44,8 +44,7 @@ void main() {
|
||||
test('can register a plugin', () {
|
||||
TestPlugin.calledMethods.clear();
|
||||
|
||||
const MethodChannel frameworkChannel =
|
||||
MethodChannel('test_plugin');
|
||||
const MethodChannel frameworkChannel = MethodChannel('test_plugin');
|
||||
frameworkChannel.invokeMethod<void>('test1');
|
||||
|
||||
expect(TestPlugin.calledMethods, equals(<String>['test1']));
|
||||
@@ -55,22 +54,20 @@ void main() {
|
||||
const StandardMessageCodec codec = StandardMessageCodec();
|
||||
|
||||
final List<String> loggedMessages = <String>[];
|
||||
ServicesBinding.instance.defaultBinaryMessenger
|
||||
.setMessageHandler('test_send', (ByteData? data) {
|
||||
ServicesBinding.instance.defaultBinaryMessenger.setMessageHandler('test_send', (
|
||||
ByteData? data,
|
||||
) {
|
||||
loggedMessages.add(codec.decodeMessage(data)! as String);
|
||||
return Future<ByteData?>.value();
|
||||
});
|
||||
|
||||
await pluginBinaryMessenger.send(
|
||||
'test_send', codec.encodeMessage('hello'));
|
||||
await pluginBinaryMessenger.send('test_send', codec.encodeMessage('hello'));
|
||||
expect(loggedMessages, equals(<String>['hello']));
|
||||
|
||||
await pluginBinaryMessenger.send(
|
||||
'test_send', codec.encodeMessage('world'));
|
||||
await pluginBinaryMessenger.send('test_send', codec.encodeMessage('world'));
|
||||
expect(loggedMessages, equals(<String>['hello', 'world']));
|
||||
|
||||
ServicesBinding.instance.defaultBinaryMessenger
|
||||
.setMessageHandler('test_send', null);
|
||||
ServicesBinding.instance.defaultBinaryMessenger.setMessageHandler('test_send', null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user