Assert that url is non-null in NetworkImage (#9626)
diff --git a/packages/flutter/lib/src/services/image_provider.dart b/packages/flutter/lib/src/services/image_provider.dart index f6e0d88..bc9423e 100644 --- a/packages/flutter/lib/src/services/image_provider.dart +++ b/packages/flutter/lib/src/services/image_provider.dart
@@ -311,7 +311,7 @@ /// Creates an object that fetches the image at the given URL. /// /// The arguments must not be null. - const NetworkImage(this.url, { this.scale: 1.0 }); + const NetworkImage(this.url, { this.scale: 1.0 }) : assert(url != null); /// The URL from which the image will be fetched. final String url;
diff --git a/packages/flutter/test/services/image_provider_test.dart b/packages/flutter/test/services/image_provider_test.dart new file mode 100644 index 0000000..4517c26 --- /dev/null +++ b/packages/flutter/test/services/image_provider_test.dart
@@ -0,0 +1,14 @@ +// Copyright 2017 The Chromium 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/services.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + test('NetworkImage non-null url test', () { + expect(() { + new NetworkImage(null); // ignore: prefer_const_constructors + }, throwsAssertionError); + }); +}