SVG in Flutter

Flutter tutorial

How to use SVG in Flutter App

Flutter Tutorial

Introduction

Flutter

Cross Platform

MVVM vs MVC vs MVP

Flutter Framework

Flutter Benefits

Flutter Comparison

Install Flutter in Win/Linux/Mac

Android Studio vs VsCode

Android Setup

VS Code Setup

VS Code Plugins

Android Studio Plugins

Flutter Widgets:

Flutter Basic Template

Flutter Commands

Top 10 Popular widgets

Flutter Stateless vs Stateful

Type of Widgets

Flutter Text widget

Flutter Text style

Textfield vs TextFormField

Flutter Scaffold

Flutter Container & SizedBox

Flutter Row & Column

Flutter Buttons

Flutter Stack

Flutter Forms

Flutter AlertDialog

Flutter Icons

Flutter Images

Flutter Drawer

Flutter ListView

Flutter GridView

Flutter Toast

Flutter Checkbox

Flutter Radio Button

Flutter Progress Bar

Flutter Tooltip

Flutter Slider

Flutter Table

Flutter SnackBar

Shimmer in Flutter

Bottom Navigation Bar in Flutter

Gesture Detector in Flutter

Error Handling in Flutter

DropDown in Flutter

Flutter Toggle

Auto Close Keyboard in Flutter

Screen size handling in Flutter

Flutter REST API

Flutter http

Flutter dio

dio vs http

Flutter Advance

Custom widget in Flutter

Flutter Navigator

Read Json in Flutter

Generate Excel in Flutter

Multiple Widgets in Flutter

Bottom sheet in Flutter

Copy to Clipboard in Flutter

Tab bar in Flutter

Code Editor in Flutter

Youtube Player in Flutter

Flutter App Development Tips

Flutter App version Update

Flutter Copy Text in App

Flutter Handle Null Value

Flutter Splash Screen

Flutter Disposable

Notification Listener

Flutter Switch Cases

Flutter Slivers

Flutter Custom App bar

Databinding in Flutter

Flutter Cards

Wrap vs Builder vs OverBarFlow

Flutter App Upgrade

GoogleMap vs FlutterMap

Circular progress contain Icon

DropDown Timer in Flutter

Flutter State management Comparison

Flutter vs Other Framework

Flutter Mixin

Passing values in Dart Files

WorkManager in Flutter

Flutter Database

Flutter Store Data

Suitable DB for Flutter

Backend for Flutter

SharedPreferences in Flutter

Flutter Token Expired Handling

Flutter Provider

Flutter Provider Tutorial

Flutter GetX

Flutter GetX tutorial

Flutter with Native

Flutter FFI

Flutter Testing

Flutter Tips

Best Practices

Reduce Flutter Screens

Tips to make app smart

Optimize App

Handle Multiple Pages

Interview Questions

Flutter 100 Interview Questions

Provider Interview Questions

GetX Interview Questions

BLoC Interview Questions

SVG (Scalable Vector Graphics) is easily expandable, has higher quality and compact file size, than PNG/JPEG. Due to the vector format, SVG type images can be easily resized without quality degradation, maintaining a responsive design across different devices. Their small file size is beneficial for fast loading times, especially for simple graphics.

Apart from the above facts, SVG supports animation, it is also SEO-friendly which allows search engines to index the content i.e good for flutter web applications. Overall, SVG is an ideal choice for mobile and web development. SVG is highly preferred in flutter and consumes less storage

SVG in Flutter

To access SVG in Flutter first add dependency in pub spec file

dependencies:
  flutter_svg: # check and add latest version of flutter_svg

Once you add flutter_svg you can use this package in any dart file, just import

import 'package:flutter_svg/flutter_svg.dart';

Here in the below code we are accessing the network SVG file in our app, you can also use any Network SVG file

SvgPicture.network(
                'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/compass.svg',
                width: 100.0,
                height: 100.0,
              ),

Here we are accessing the local SVG file which we store in the assets folder and add the path in the pub spec file

SvgPicture.asset(
                localAsset,
                width: 300.0,
                height: 300.0,
              ),

Network SVG & Local Assets SVG Example in Flutter

In the below code which can show multiple SVG images locally and network in flutter app

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
final String localAsset = 'assets/compass.svg';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('ResearchThinker: SVG in Flutter'),
        ),
        body: Column(
          children: [
            Center(
              child: SvgPicture.network(
                'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/compass.svg',
                width: 100.0,
                height: 100.0,
              ),
            ),
            Divider(thickness: 2,),
            Center(
              child: SvgPicture.network(
                'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/compass.svg',

              ),
            ),
            Divider(thickness: 2,),
            Center(
              child: SvgPicture.network(
                'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/compass.svg',
                width: 200.0,
                height: 200.0,
              ),
            ),
            Divider(thickness: 2,),
            Center(
              child: SvgPicture.asset(
                localAsset,
                width: 300.0,
                height: 300.0,
              ),
            ),
          ],
        ),
      ),
    );
  }
}


Leave a Reply

Your email address will not be published. Required fields are marked *

web_horizontal
About Us ♢ Disclaimer ♢ Privacy Policy ♢ Terms & Conditions ♢ Contact Us

Copyright © 2023 ResearchThinker.com. All rights reserved.