more const for immutables (#10563)
This commit is contained in:
committed by
GitHub
parent
dfc7788c8e
commit
1eaefe1837
@@ -35,7 +35,7 @@ abstract class MessageCodec<T> {
|
||||
class MethodCall {
|
||||
/// Creates a [MethodCall] representing the invocation of [method] with the
|
||||
/// specified [arguments].
|
||||
MethodCall(this.method, [this.arguments])
|
||||
const MethodCall(this.method, [this.arguments])
|
||||
: assert(method != null);
|
||||
|
||||
/// The name of the method to be called.
|
||||
|
||||
@@ -46,7 +46,7 @@ class _ActiveItem implements Comparable<_ActiveItem> {
|
||||
/// This widget is similar to one created by [ListView.builder].
|
||||
class AnimatedList extends StatefulWidget {
|
||||
/// Creates a scrolling container that animates items when they are inserted or removed.
|
||||
AnimatedList({
|
||||
const AnimatedList({
|
||||
Key key,
|
||||
@required this.itemBuilder,
|
||||
this.initialItemCount: 0,
|
||||
|
||||
@@ -195,7 +195,7 @@ class AsyncSnapshot<T> {
|
||||
const AsyncSnapshot.nothing() : this._(ConnectionState.none, null, null);
|
||||
|
||||
/// Creates an [AsyncSnapshot] in the specified [state] and with the specified [data].
|
||||
AsyncSnapshot.withData(ConnectionState state, T data) : this._(state, data, null); // not const because https://github.com/dart-lang/sdk/issues/29432
|
||||
const AsyncSnapshot.withData(ConnectionState state, T data) : this._(state, data, null);
|
||||
|
||||
/// Creates an [AsyncSnapshot] in the specified [state] and with the specified [error].
|
||||
const AsyncSnapshot.withError(ConnectionState state, Object error) : this._(state, null, error);
|
||||
|
||||
@@ -313,10 +313,10 @@ class LabeledGlobalKey<T extends State<StatefulWidget>> extends GlobalKey<T> {
|
||||
/// Creates a global key with a debugging label.
|
||||
///
|
||||
/// The label does not affect the key's identity.
|
||||
const LabeledGlobalKey(this._debugLabel) : super.constructor();
|
||||
LabeledGlobalKey(this._debugLabel) : super.constructor();
|
||||
|
||||
// Used for forwarding the constructor from GlobalKey.
|
||||
const LabeledGlobalKey._({ String debugLabel }) : _debugLabel = debugLabel, super.constructor();
|
||||
LabeledGlobalKey._({ String debugLabel }) : _debugLabel = debugLabel, super.constructor();
|
||||
|
||||
final String _debugLabel;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ typedef List<Widget> NestedScrollViewHeaderSliversBuilder(BuildContext context,
|
||||
const double _kInitialScrollOffset = 0.0;
|
||||
|
||||
class NestedScrollView extends StatefulWidget {
|
||||
NestedScrollView({
|
||||
const NestedScrollView({
|
||||
Key key,
|
||||
this.scrollDirection: Axis.vertical,
|
||||
this.reverse: false,
|
||||
|
||||
@@ -15,6 +15,6 @@ void main() {
|
||||
|
||||
await HapticFeedback.vibrate();
|
||||
|
||||
expect(log, equals(<MethodCall>[new MethodCall('HapticFeedback.vibrate')]));
|
||||
expect(log, equals(<MethodCall>[const MethodCall('HapticFeedback.vibrate')]));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ void main() {
|
||||
});
|
||||
test('can handle method call with no registered plugin', () async {
|
||||
channel.setMethodCallHandler(null);
|
||||
final ByteData call = jsonMethod.encodeMethodCall(new MethodCall('sayHello', 'hello'));
|
||||
final ByteData call = jsonMethod.encodeMethodCall(const MethodCall('sayHello', 'hello'));
|
||||
ByteData envelope;
|
||||
await BinaryMessages.handlePlatformMessage('ch7', call, (ByteData result) {
|
||||
envelope = result;
|
||||
@@ -102,7 +102,7 @@ void main() {
|
||||
channel.setMethodCallHandler((MethodCall call) async {
|
||||
throw new MissingPluginException();
|
||||
});
|
||||
final ByteData call = jsonMethod.encodeMethodCall(new MethodCall('sayHello', 'hello'));
|
||||
final ByteData call = jsonMethod.encodeMethodCall(const MethodCall('sayHello', 'hello'));
|
||||
ByteData envelope;
|
||||
await BinaryMessages.handlePlatformMessage('ch7', call, (ByteData result) {
|
||||
envelope = result;
|
||||
@@ -111,7 +111,7 @@ void main() {
|
||||
});
|
||||
test('can handle method call with successful result', () async {
|
||||
channel.setMethodCallHandler((MethodCall call) async => '${call.arguments}, world');
|
||||
final ByteData call = jsonMethod.encodeMethodCall(new MethodCall('sayHello', 'hello'));
|
||||
final ByteData call = jsonMethod.encodeMethodCall(const MethodCall('sayHello', 'hello'));
|
||||
ByteData envelope;
|
||||
await BinaryMessages.handlePlatformMessage('ch7', call, (ByteData result) {
|
||||
envelope = result;
|
||||
@@ -122,7 +122,7 @@ void main() {
|
||||
channel.setMethodCallHandler((MethodCall call) async {
|
||||
throw new PlatformException(code: 'bad', message: 'sayHello failed', details: null);
|
||||
});
|
||||
final ByteData call = jsonMethod.encodeMethodCall(new MethodCall('sayHello', 'hello'));
|
||||
final ByteData call = jsonMethod.encodeMethodCall(const MethodCall('sayHello', 'hello'));
|
||||
ByteData envelope;
|
||||
await BinaryMessages.handlePlatformMessage('ch7', call, (ByteData result) {
|
||||
envelope = result;
|
||||
@@ -141,7 +141,7 @@ void main() {
|
||||
channel.setMethodCallHandler((MethodCall call) async {
|
||||
throw new ArgumentError('bad');
|
||||
});
|
||||
final ByteData call = jsonMethod.encodeMethodCall(new MethodCall('sayHello', 'hello'));
|
||||
final ByteData call = jsonMethod.encodeMethodCall(const MethodCall('sayHello', 'hello'));
|
||||
ByteData envelope;
|
||||
await BinaryMessages.handlePlatformMessage('ch7', call, (ByteData result) {
|
||||
envelope = result;
|
||||
|
||||
@@ -15,6 +15,6 @@ void main() {
|
||||
|
||||
await SystemNavigator.pop();
|
||||
|
||||
expect(log, equals(<MethodCall>[new MethodCall('SystemNavigator.pop')]));
|
||||
expect(log, equals(<MethodCall>[const MethodCall('SystemNavigator.pop')]));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import 'package:test/test.dart';
|
||||
void main() {
|
||||
test('System sound control test', () async {
|
||||
final List<MethodCall> log = <MethodCall>[];
|
||||
|
||||
|
||||
SystemChannels.platform.setMockMethodCallHandler((MethodCall methodCall) async {
|
||||
log.add(methodCall);
|
||||
});
|
||||
|
||||
|
||||
await SystemSound.play(SystemSoundType.click);
|
||||
|
||||
expect(log, equals(<MethodCall>[new MethodCall('SystemSound.play', "SystemSoundType.click")]));
|
||||
expect(log, equals(<MethodCall>[const MethodCall('SystemSound.play', "SystemSoundType.click")]));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ void main() {
|
||||
group('AsyncSnapshot', () {
|
||||
test('requiring data succeeds if data is present', () {
|
||||
expect(
|
||||
new AsyncSnapshot<String>.withData(ConnectionState.done, 'hello').requireData,
|
||||
const AsyncSnapshot<String>.withData(ConnectionState.done, 'hello').requireData,
|
||||
'hello',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ import 'package:flutter/src/widgets/layout_builder.dart';
|
||||
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher;
|
||||
|
||||
class Wrapper extends StatelessWidget {
|
||||
Wrapper({
|
||||
const Wrapper({
|
||||
Key key,
|
||||
@required this.child
|
||||
}) : assert(child != null),
|
||||
|
||||
Reference in New Issue
Block a user