svg_pic_editor
複数のプラットフォームでSVGの編集および操作を行うためのFlutterパッケージ。
vs-nascimento/svg_pic_editor open-source repository details.
以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
SvgPicEditor is a Flutter widget that allows you to load and modify SVG files from various sources, such as local assets, SVG strings, or URLs. This widget also lets you modify specific SVG elements using the ElementEdit class, making it easy to change properties like color, opacity, transformations, and more. The new listenEdit and getColors features further expand the possibilities for manipulating and customizing SVGs.
To add SvgPicEditor to your Flutter project, include the following in your pubspec.yaml:
dependencies:
svg_pic_editor: ^3.0.0
Or run the command:
flutter pub add svg_pic_editor
To use SvgPicEditor, import the package into your Dart file:
import 'package:svg_pic_editor/svg_pic_editor.dart';
Here is a basic example of how to use SvgPicEditor inside a Flutter widget:
import 'package:flutter/material.dart';
import 'package:svg_pic_editor/svg_pic_editor.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('SvgPicEditor Example')),
body: Center(
child: SvgPicEditor.asset(
'assets/example.svg',
modifications: [
ElementEdit(
querySelector: '#element1',
fillColor: Colors.red,
),
],
width: 200.0,
height: 200.0,
fit: BoxFit.contain,
listenEdit: (svgContent) {
print('Edited SVG content: $svgContent');
},
onTap: (modifiedSvgString) {
print('Tapped SVG: $modifiedSvgString');
},
),
),
),
);
}
}
This example loads an SVG file from a local asset, modifies it, and adds the onTap callback to handle tap actions, printing either the modified SVG string or no value at all.
Loads an SVG from a local asset:
SvgPicEditor.asset(
'assets/your_file.svg',
modifications: [/* List of ElementEdit */],
width: 100.0,
height: 100.0,
fit: BoxFit.contain,
querySelector: '#yourID',
color: Colors.red,
listenEdit: (svgContent) => print('Updated SVG: $svgContent'),
onTap: (modifiedSvgString) => print('Tapped SVG: $modifiedSvgString'),
);
Loads an SVG from a URL:
SvgPicEditor.network(
'https://example.com/your/svg.svg',
modifications: [/* List of ElementEdit */],
width: 100.0,
height: 100.0,
fit: BoxFit.contain,
querySelector: '.yourClass',
color: Colors.red,
listenEdit: (svgContent) => print('SVG content: $svgContent'),
onTap: (modifiedSvgString) => print('Tapped SVG: $modifiedSvgString'),
);
Loads an SVG from an SVG string:
SvgPicEditor.string(
'<svg>...</svg>',
modifications: [/* List of ElementEdit */],
width: 100.0,
height: 100.0,
fit: BoxFit.contain,
querySelector: '[attribute="value"]',
color: Colors.red,
listenEdit: (svgContent) => print('Updated SVG: $svgContent'),
onTap: (modifiedSvgString) => print('Tapped SVG: $modifiedSvgString'),
);
Main properties of the SvgPicEditor widget:
The ElementEdit class allows you to make specific modifications to SVG elements, such as changing the color, opacity, or applying transformations.
class ElementEdit {
final String? id;
final Color? fillColor;
final Color? strokeColor;
final double? strokeWidth;
final double? opacity;
final String? transform;
final String? querySelector;
ElementEdit({
this.id,
this.fillColor,
this.strokeColor,
this.strokeWidth,
this.opacity,
this.transform,
this.querySelector,
});
}
The listenEdit feature allows you to listen for edits made to the SVG content and get updates about the modified SVG.
SvgPicEditor.asset(
'assets/example.svg',
modifications: [
ElementEdit(
querySelector: '#element1',
fillColor: Colors.red,
),
],
width: 200.0,
height: 200.0,
fit: BoxFit.contain,
listenEdit: (svgContent) {
// Whenever the SVG is edited, the updated content will be printed
print('Edited SVG content: $svgContent');
},
);
The getColors feature allows you to extract color information from an SVG. It returns an SvgColorElement containing the color and the elements associated with it in the SVG.
SvgPicEditor.asset(
'assets/example.svg',
modifications: [
ElementEdit(
querySelector: '#element1',
fillColor: Colors.red,
),
],
width: 200.0,
height: 200.0,
fit: BoxFit.contain,
getColor: (List<SvgColorElement> colors) {
// Retrieve the colors and associated elements from the SVG
colors.forEach((colorElement) {
print('Color: ${colorElement.color}');
colorElement.parts.forEach((part) { // List of associated elements
print('Element: ${part.querySelector}');
});
});
},
);
With the new listenEdit, getColors, and onTap features, SvgPicEditor becomes an even more powerful and flexible tool for manipulating and customizing SVGs in Flutter. Now, in addition to modifying SVG elements, you can track real-time edits, extract valuable information about the colors and elements within the SVG, and trigger actions when the SVG is tapped.
If you would like to support the development of this project, you can make a contribution through PayPal. Your support helps keep the development active and adds new features.
You can make your donation by scanning the QR code below:
We truly appreciate your support!
onTap functionality, now supporting both void and modified SVG string returns for better flexibility.SvgPicEditor widget, ensuring smoother user experience when errors occur.modifiedSvgString update logic to improve the reactivity and ensure faster rendering.onTap callback function, allowing users to trigger actions when the SVG is tapped, either with the modified SVG string or without any return value.
依存関係一覧 6 件
{"sdk":"flutter"}^2.0.10^1.2.2^6.5.0{"sdk":"flutter"}^4.0.0用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗