blob: be0bf47a1c1b21be0397f2bb09e8edd08a09f3d5 [file] [log] [blame]
// 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);
}
});
}