Skip to content

Commit 44a8ce1

Browse files
authored
[flutter_image] Adopt code excerpts in README (flutter#5498)
Updates the README to use a compiled excerpt source for its example of using `NetworkImageWithRetry`. Part of [flutter#102679](flutter#102679)
1 parent 7a11e2d commit 44a8ce1

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

packages/flutter_image/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Fixes image asset link to use image within package.
44
* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
5+
* Updates README to improve example of using `NetworkImageWithRetry`.
56

67
## 4.1.9
78

packages/flutter_image/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ network with a retry mechanism.
77

88
Example:
99

10+
<?code-excerpt "example/lib/readme_excerpts.dart (NetworkImageWithRetry)"?>
1011
```dart
11-
var avatar = new Image(
12-
image: new NetworkImageWithRetry('http://example.com/avatars/123.jpg'),
12+
const Image avatar = Image(
13+
image: NetworkImageWithRetry('http://example.com/avatars/123.jpg'),
1314
);
1415
```
1516

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/widgets.dart';
6+
import 'package:flutter_image/flutter_image.dart';
7+
8+
/// Demonstrates loading an image for the README.
9+
Image networkImageWithRetry() {
10+
// #docregion NetworkImageWithRetry
11+
const Image avatar = Image(
12+
image: NetworkImageWithRetry('http://example.com/avatars/123.jpg'),
13+
);
14+
// #enddocregion NetworkImageWithRetry
15+
16+
return avatar;
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/widgets.dart';
6+
import 'package:flutter_image/flutter_image.dart';
7+
import 'package:flutter_image_example/readme_excerpts.dart';
8+
import 'package:flutter_test/flutter_test.dart';
9+
10+
void main() {
11+
test('networkImageWithRetry returns an Image with NetworkImageWithRetry', () {
12+
// Ensure that the snippet code runs successfully.
13+
final Image result = networkImageWithRetry();
14+
15+
// It should have a image property of the right type.
16+
expect(result.image, isInstanceOf<NetworkImageWithRetry>());
17+
// And the NetworkImageWithRetry should have a url property.
18+
final NetworkImageWithRetry networkImage =
19+
result.image as NetworkImageWithRetry;
20+
expect(networkImage.url, equals('http://example.com/avatars/123.jpg'));
21+
});
22+
}

script/configs/temp_exclude_excerpt.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
- css_colors
99
- espresso
1010
- extension_google_sign_in_as_googleapis_auth
11-
- flutter_image
1211
- go_router_builder
1312
- google_sign_in/google_sign_in
1413
- image_picker_for_web

0 commit comments

Comments
 (0)