Skip to content

Commit 0c97067

Browse files
Add test for image.frame_builder.0.dart (#158247)
Contributes to flutter/flutter#130459 It adds a test for - `examples/api/lib/widgets/image/image.frame_builder.0.dart`
1 parent 4bc83fe commit 0c97067

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,4 @@ class SampleChecker {
310310
// See https://github.com/flutter/flutter/issues/130459
311311
final Set<String> _knownMissingTests = <String>{
312312
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
313-
'examples/api/test/widgets/image/image.frame_builder.0_test.dart',
314313
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2014 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 'dart:io';
6+
7+
import 'package:flutter/material.dart';
8+
import 'package:flutter_api_samples/widgets/image/image.frame_builder.0.dart'
9+
as example;
10+
import 'package:flutter_test/flutter_test.dart';
11+
12+
void main() {
13+
// The app being tested loads images via HTTP which the test
14+
// framework defeats by default.
15+
setUpAll(() {
16+
HttpOverrides.global = null;
17+
});
18+
19+
testWidgets('The frame builder returns an AnimatedOpacity when not synchronously loaded', (WidgetTester tester) async {
20+
await tester.pumpWidget(
21+
const example.FrameBuilderExampleApp(),
22+
);
23+
await tester.pumpAndSettle();
24+
25+
final Image image = tester.widget<Image>(find.byType(Image));
26+
final ImageFrameBuilder frameBuilder = image.frameBuilder!;
27+
final BuildContext context = tester.element(find.byType(Image));
28+
29+
const Key key = Key('child');
30+
31+
expect(
32+
frameBuilder(context, const SizedBox(key: key), null, false),
33+
isA<AnimatedOpacity>().having(
34+
(AnimatedOpacity opacity) => opacity.child!.key, 'key', key,
35+
),
36+
);
37+
});
38+
39+
testWidgets('The frame builder returns the child when synchronously loaded', (WidgetTester tester) async {
40+
await tester.pumpWidget(
41+
const example.FrameBuilderExampleApp(),
42+
);
43+
await tester.pumpAndSettle();
44+
45+
final Image image = tester.widget<Image>(find.byType(Image));
46+
final ImageFrameBuilder frameBuilder = image.frameBuilder!;
47+
final BuildContext context = tester.element(find.byType(Image));
48+
49+
const Key key = Key('child');
50+
51+
expect(
52+
frameBuilder(context, const SizedBox(key: key), null, true),
53+
isA<SizedBox>().having(
54+
(SizedBox widget) => widget.key, 'key', key,
55+
),
56+
);
57+
});
58+
}

0 commit comments

Comments
 (0)