Skip to content

Commit 1cc9a5c

Browse files
authored
Cleanup readme (#2036)
1 parent 14fd53a commit 1cc9a5c

File tree

1 file changed

+48
-54
lines changed

1 file changed

+48
-54
lines changed

case_study/memory_leaks/images_1/README.md

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,54 @@ A material design widget to view downloaded network images.
66

77
**Solution:** Fix the ListView.builder add the parameters cacheHeight and cacheWidth to the Image.network constructor e.g.,
88

9-
Look for:
10-
```
11-
Widget listView() => ListView.builder
12-
```
13-
14-
Find the Image.network constructor then add the below parameters:
15-
16-
```
17-
// Decode image to a specified height and width (ResizeImage).
18-
cacheHeight: 1024,
19-
cacheWidth: 1024,
20-
```
21-
Original code:
22-
23-
```
24-
final image = Image.network(
25-
imgUrl,
26-
width: 750.0,
27-
height: 500,
28-
scale: 1.0,
29-
fit: BoxFit.fitWidth,
30-
loadingBuilder: (
31-
BuildContext context,
32-
Widget child,
33-
ImageChunkEvent loadingProgress,
34-
) {
35-
if (loadingProgress == null) return child;
36-
return recordLoadedImage(loadingProgress, imgUrl);
37-
},
38-
);
39-
```
40-
41-
Fixed code:
42-
43-
```
44-
final image = Image.network(
45-
imgUrl,
46-
width: 750.0,
47-
height: 500,
48-
scale: 1.0,
49-
// Decode image to a specified height and width (ResizeImage).
50-
cacheHeight: 1024,
51-
cacheWidth: 1024,
52-
fit: BoxFit.fitWidth,
53-
loadingBuilder: (
54-
BuildContext context,
55-
Widget child,
56-
ImageChunkEvent loadingProgress,
57-
) {
58-
if (loadingProgress == null) return child;
59-
return recordLoadedImage(loadingProgress, imgUrl);
60-
},
61-
);
62-
```
9+
Look for:
10+
11+
Widget listView() => ListView.builder
12+
13+
Find the Image.network constructor then add the below parameters:
14+
15+
// Decode image to a specified height and width (ResizeImage).
16+
cacheHeight: 1024,
17+
cacheWidth: 1024,
18+
19+
Original code:
20+
21+
final image = Image.network(
22+
imgUrl,
23+
width: 750.0,
24+
height: 500,
25+
scale: 1.0,
26+
fit: BoxFit.fitWidth,
27+
loadingBuilder: (
28+
BuildContext context,
29+
Widget child,
30+
ImageChunkEvent loadingProgress,
31+
) {
32+
if (loadingProgress == null) return child;
33+
return recordLoadedImage(loadingProgress, imgUrl);
34+
},
35+
);
36+
37+
Fixed code:
38+
39+
final image = Image.network(
40+
imgUrl,
41+
width: 750.0,
42+
height: 500,
43+
scale: 1.0,
44+
// Decode image to a specified height and width (ResizeImage).
45+
cacheHeight: 1024,
46+
cacheWidth: 1024,
47+
fit: BoxFit.fitWidth,
48+
loadingBuilder: (
49+
BuildContext context,
50+
Widget child,
51+
ImageChunkEvent loadingProgress,
52+
) {
53+
if (loadingProgress == null) return child;
54+
return recordLoadedImage(loadingProgress, imgUrl);
55+
},
56+
);
6357

6458
The parameters cacheWidth or cacheHeight indicates to the engine that the image should be decoded at the specified size e.g., thumbnail. If not specified the full image will be used each time when all that is needed is a much smaller image. The image will be rendered to the constraints of the layout or width and height regardless of these parameters. These parameters are intended to reduce the memory usage of ImageCache
6559

0 commit comments

Comments
 (0)