Flutter - How to Use SVG Image
Last Updated :
28 Apr, 2025
SVG (Scalable Vector Graphics) is a vector image format that can be used to create high-quality, resolution-independent graphics. In Flutter, you can use SVG images to display vector graphics in your app. To use SVG images in Flutter, you can use the flutter_svg package to display SVG images in Flutter. This package provides a widget called SvgPicture that allows you to display SVG images.
How to Use?
Dart
SvgPicture.asset(
'assets/images/s1.svg',
semanticsLabel: 'My SVG Image',
height: 100,
width: 70,
),
Before going to use it, you have to add the flutter_svg dependency in pubspec.yaml file.
Step By Step Implementation
Step 1: Create a New Project in Android Studio or in VS code
To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter. And add the asset SVG image.
Step 2: Install the package
Add the dependency into pubspec.yaml file.
dependencies:
flutter_svg: ^2.0.5
and then import the package into the file where you want to use it.
import 'package:flutter_svg/flutter_svg.dart';
Step 3: Import the Material Package
A material package gives us the essential functions and Parameters, now call the runApp method that needs an Application in the main function.
import 'package:flutter/material.dart';
void main() {
runApp(RunMyApp());
}
In the above code, runApp method calls the class RunMyApp, Now we have to create it.
Step 4: Creating Stateless Widget
Now we have to make a stateless widget because our application does not go to change its state and then return the MaterialApp widget which allows us the set the title and theme and many more of the application.
Shortcut for creating a stateless or Stateful widget: You can create a stateless widget by just typing three alphabets ‘stl’ and you can see a stateless widget and then hit enter.
class RunMyApp extends StatelessWidget {
const RunMyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.green),
home:
);
}
}
Step 5:
We can use the Material widget instead of scaffold, Further then we can simply use the SvgPicture widget to display the svg image.
home: Material(
child: Center(
child: SvgPicture.asset(
'assets/images/s1.svg',
semanticsLabel: 'My SVG Image',
height: 100,
width: 70,
),
),
),
Code Example
Dart
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
void main() {
runApp(RunMyApp());
}
class RunMyApp extends StatelessWidget {
const RunMyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.green),
home: Material(
child: Center(
child: SvgPicture.asset(
'assets/images/s1.svg',
semanticsLabel: 'My SVG Image',
height: 100,
width: 70,
),
),
),
);
}
}
Make sure to replace 'assets/images/s1.svg' with the path to your SVG file.
Output
Similar Reads
How to Use 3D Models in Flutter? Flutter has recently developed into the realm of 3D graphics, expanding its capabilities beyond just 2D applications. In this article, we will explore the exciting process of creating 3D objects in Flutter using the flutter_cube library. Steps to Implement 3D Models in FlutterStep 1: Create a new Fl
4 min read
How to Create a Zoomable Image in Flutter? In Flutter, you can create a zoomable image using the GestureDetector and Transform widgets. The GestureDetector widget can be used to detect pinch gestures on the image, and the Transform widget can be used to apply the zoom transformation to the image. How to Use:Container( child: PhotoView( image
3 min read
How to Install Flutter on Windows? Flutter is Google's portable user interface (UI) toolkit. It is used to build and develop eye-catching, natively built mobile, desktop, and web applications from a single codebase. Flutter is free, open-sourced, and compatible with existing code. Due to its user-friendly interface and fairly simple
8 min read
Flutter - OctoImage Widget The OctoImage widget in Flutter requires an ImageProvider to display images in an application. The images in the OctoImage widget can be supplied with a Progress indicator or a Place holder for loading the Image in it. An OctoImage widget makes use of the Octosets which are nothing but the combinati
4 min read
Flutter - SVG Image as Button In this article, we will see how to make the SVG image a button in Flutter so that we can perform actions. A sample video is given below to get an idea about what we are going to do in this article. How to Use? You can use the Gesture Detector to add click functionality to any Widget in Flutter. Dar
2 min read