I’ve been dealing with this problem for a while now: even though I’m using the flutter_svg package, my SVG file won’t appear in the emulator. The SVG is just a simple droplet icon with an outline, which I wanted to display in the middle of the screen as a test. But absolutely nothing shows up.
The same thing happens with other SVG files as well, while PNGs work perfectly fine. I’ve attached my main.dart file, pubspec.yaml, and a screenshot below.
name: fluttertest
description: "A new Flutter project."
publish_to: "none"
version: 1.0.0+1
environment:
sdk: ^3.12.1
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.8
flutter_svg: ^2.3.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^6.0.0
flutter:
uses-material-design: true
assets:
- assets/tropfen.svg
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
const _dropAsset = 'assets/tropfen.svg';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(colorScheme: .fromSeed(seedColor: Colors.deepPurple)),
home: Background(),
);
}
}
class Background extends StatelessWidget {
const Background({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.red,
body: Center(
child: SvgPicture.asset(
_dropAsset,
width: 180,
height: 260,
fit: BoxFit.contain,
colorFilter: const ColorFilter.mode(
Color.fromARGB(255, 255, 255, 255),
BlendMode.srcIn,
),
semanticsLabel: 'Tropfen',
),
),
);
}
}