import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_svg/src/picture_cache.dart';
import 'package:flutter_svg/src/picture_provider.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:xml/xml.dart';
class MockPictureStreamCompleter extends PictureStreamCompleter {}
void main() {
PictureCache cache;
setUp(() {
cache = PictureCache();
});
testWidgets('Precache test', (WidgetTester tester) async {
const String svgString = '''''';
const String svgString2 = '''''';
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Text('test_text'),
),
);
expect(PictureProvider.cacheCount, 0);
await precachePicture(
StringPicture(
SvgPicture.svgStringDecoder,
svgString,
),
tester.element(find.text('test_text')),
);
expect(PictureProvider.cacheCount, 1);
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: SvgPicture.string(svgString),
),
);
expect(PictureProvider.cacheCount, 1);
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: SvgPicture.string(svgString2),
),
);
expect(PictureProvider.cacheCount, 2);
PictureProvider.clearCache();
expect(PictureProvider.cacheCount, 0);
});
testWidgets('Precache - null context', (WidgetTester tester) async {
const String svgString = '''''';
expect(PictureProvider.cacheCount, 0);
await precachePicture(
StringPicture(
SvgPicture.svgStringDecoder,
svgString,
),
null,
);
expect(PictureProvider.cacheCount, 1);
});
testWidgets('Precache with error', (WidgetTester tester) async {
const String svgString = '