Skip to content

Commit

Permalink
Merge pull request #32 from bamlab/feat/improve-await-images
Browse files Browse the repository at this point in the history
Feat/improve await images
  • Loading branch information
T-moz authored Sep 15, 2024
2 parents bd110e5 + 6d5c949 commit cc02330
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* feat: awaitImages now support FadeInImage.
* improvement: use pump instead of pumpAndSettle in awaitImages.
* feat: add path and version argument to expectGolden method.

## 0.5.1
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions example/simple_app/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import 'view/home.dart';
import 'package:flutter/material.dart';

class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
const App({
Key? key,
this.useFadeInImage = false,
}) : super(key: key);

final bool useFadeInImage;

@override
Widget build(BuildContext context) {
Expand All @@ -13,7 +18,9 @@ class App extends StatelessWidget {
primarySwatch: Colors.blue,
fontFamily: 'roboto',
),
home: const HomeLayout(),
home: HomeLayout(
useFadeInImage: useFadeInImage,
),
);
}
}
20 changes: 14 additions & 6 deletions example/simple_app/lib/src/view/home.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter/material.dart';

class HomeLayout extends StatelessWidget {
const HomeLayout({Key? key}) : super(key: key);
const HomeLayout({Key? key, this.useFadeInImage = false}) : super(key: key);

final bool useFadeInImage;
@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -15,11 +16,18 @@ class HomeLayout extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/dash.png',
height: 56,
width: 56,
),
useFadeInImage
? const FadeInImage(
placeholder: AssetImage('assets/dash.png'),
image: AssetImage('assets/dash.png'),
height: 56,
width: 56,
)
: Image.asset(
'assets/dash.png',
height: 56,
width: 56,
),
const SizedBox(width: 20),
const Expanded(
child: TextField(
Expand Down
14 changes: 14 additions & 0 deletions example/simple_app/test/src/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ void main() {
);
},
);
testAdaptiveWidgets(
'$App render with FadeInImage',
(tester, variant) async {
await tester.pumpWidget(
AdaptiveWrapper(
windowConfig: variant,
tester: tester,
child: const App(),
),
);

await tester.expectGolden<App>(variant, suffix: 'fade_in_image');
},
);
testAdaptiveWidgets(
'$App render with custom path',
(tester, variant) async {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions lib/src/helpers/await_images.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

Expand All @@ -11,7 +13,18 @@ extension AwaitImages on WidgetTester {
final widget = element.widget as Image;
final image = widget.image;
await precacheImage(image, element);
await pumpAndSettle();
await pump();
}

for (final element in find.byType(FadeInImage).evaluate().toList()) {
final widget = element.widget as FadeInImage;
final image = widget.image;
final pumpDurationInMilliseconds = max(
widget.fadeInDuration.inMilliseconds,
widget.fadeOutDuration.inMilliseconds,
);
await precacheImage(image, element);
await pump(Duration(milliseconds: pumpDurationInMilliseconds));
}

for (final element in find.byType(DecoratedBox).evaluate().toList()) {
Expand All @@ -21,7 +34,7 @@ extension AwaitImages on WidgetTester {
final image = decoration.image?.image;
if (image != null) {
await precacheImage(image, element);
await pumpAndSettle();
await pump();
}
}
}
Expand Down

0 comments on commit cc02330

Please sign in to comment.