Flutter - How to Use SVG Image
Last Updated :
24 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
Flutter - Make an HTTP POST Request
In app development, the ability to fetch data from external sources, such as REST APIs, is a fundamental requirement. In Flutter, whether you need to send some data to the RESTful API, access a database, or then Send content from the Flutter App, Flutter provides you with the tools and packages(HTTP
5 min read
Rounded Corner Image in Flutter
Rounded images or avatars are commonly used in many mobile applications, including those built with Flutter. There are several ways to create rounded images in Flutter, some of which include: Using the ClipRRect widget: As I mentioned earlier, the ClipRRect widget can be used to clip an image and cr
3 min read
How to Install Flutter on Linux?
In this article, we will learn how to install Flutter in Linux Flutter is an open-source UI software development kit created by Google. It is used to develop cross-platform applications for Android, iOS, Linux, Mac, Windows, Google Fuchsia, and the web from a single codebase. Installing Flutter on L
2 min read
Flutter - Display Text Over the Image
In this article, we will implement How the set the text on over the Image in Flutter. A sample image is given below to get an idea about what we are going to do in this article. Â Approach In Data structure everyone knows the stack linear data structure, Stack is nothing just placing an item one over
3 min read
Flutter - Value Notifier
If you are a flutter developer then you must have heard about the state management. You have knowledge of that. If you are new to this topic then we will learn a little bit more about it. You can refer to Flutter â State Management. Do you know other than setState there is more state management you
3 min read