Assert that url is non-null in NetworkImage (#9626)

This commit is contained in:
Todd Volkert 2017-04-26 21:35:58 -07:00 committed by GitHub
parent 2e194d5b44
commit 9558ac7d55
2 changed files with 15 additions and 1 deletions

View file

@ -311,7 +311,7 @@ class NetworkImage extends ImageProvider<NetworkImage> {
/// 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;

View file

@ -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);
});
}