blob: 0d5ce13f6e1d8c6d71a820f7073f3e5d72050509 [file] [log] [blame] [edit]
// Copyright 2019 The Flutter 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 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart' as path;
/// Precaches the images in the `assets` folder. This method must be called
/// before pumping any widgets.
Future<void> precacheTaskIcons(WidgetTester tester) async {
// Depending on how we're invoked, Platform.script.path will have extra parts
// after app_flutter. Just trim them off.
final pathParts = path.split(Platform.script.path);
while (pathParts.last != 'dashboard') {
pathParts.removeLast();
}
final assetPath = path.joinAll(<String>[...pathParts, 'assets']);
final assets = Directory(assetPath)
.listSync()
.map((FileSystemEntity entity) => path.basename(entity.path))
.toList();
await tester.pumpWidget(const SizedBox());
await tester.runAsync(() async {
for (final asset in assets) {
final ImageProvider provider = ExactAssetImage('assets/$asset');
await provider.evict();
await precacheImage(provider, tester.allElements.first);
}
});
}