xxxxxxxxxx
flutter pub add flutter_svg
import 'package:flutter_svg/flutter_svg.dart';
SvgPicture.asset("images/doughnut.svg")
xxxxxxxxxx
dependencies:
flutter_svg: ^0.18.0
flutter pub get
import 'package:flutter_svg/flutter_svg.dart';
SvgPicture.asset("images/doughnut.svg")
xxxxxxxxxx
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class SvgImageScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SVG Image'),
),
body: Center(
child: SvgPicture.asset(
'assets/images/sample.svg', // Replace with your SVG image path
height: 200,
width: 200,
),
),
);
}
}
xxxxxxxxxx
new SvgPicture.asset(
'assets/images/candle.svg',
height: 20.0,
width: 20.0,
allowDrawingOutsideViewBox: true,
),
xxxxxxxxxx
import 'package:flutter_svg/flutter_svg.dart';
// ...
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SVG Image Example'),
),
body: Center(
child: SvgPicture.asset(
'assets/images/example.svg', // Replace with your SVG image file path
height: 200, // Adjust the height as needed
width: 200, // Adjust the width as needed
),
),
);
}
xxxxxxxxxx
final String assetName = 'assets/image.svg';
final Widget svg = SvgPicture.asset(
assetName,
semanticsLabel: 'Acme Logo'
);
xxxxxxxxxx
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class MySvgIcon extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SvgPicture.asset(
'assets/icons/my_icon.svg',
// You can provide additional properties for customization
width: 24,
height: 24,
color: Colors.red,
// ...
);
}
}
xxxxxxxxxx
// ImageProvider does not support SvgPicture.asset()
// the following code will throw an error because flutter_svg package is not compatible with image provider
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: SvgPicture.asset(''),
),
),
),
// instead, you can use flutter_svg_provider package. It suppports image provider