-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial merge commit from dnfield/flutter_svg with no changes other than file locations.
- Loading branch information
Showing
274 changed files
with
10,791 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2018 Dan Field | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# flutter_svg | ||
|
||
[![Pub](https://img.shields.io/pub/v/flutter_svg.svg)](https://pub.dartlang.org/packages/flutter_svg) [![Coverage Status](https://coveralls.io/repos/github/dnfield/flutter_svg/badge.svg?branch=master)](https://coveralls.io/github/dnfield/flutter_svg?branch=master) | ||
|
||
<!-- markdownlint-disable MD033 --> | ||
<img src="https://raw.githubusercontent.com/dnfield/flutter_svg/7d374d7107561cbd906d7c0ca26fef02cc01e7c8/example/assets/flutter_logo.svg?sanitize=true" width="200px" alt="Flutter Logo which can be rendered by this package!"> | ||
<!-- markdownlint-enable MD033 --> | ||
|
||
Draw SVG files using Flutter. | ||
|
||
## Getting Started | ||
|
||
Basic usage (to create an SVG rendering widget from an asset): | ||
|
||
```dart | ||
final String assetName = 'assets/image.svg'; | ||
final Widget svg = SvgPicture.asset( | ||
assetName, | ||
semanticsLabel: 'Acme Logo' | ||
); | ||
``` | ||
|
||
You can color/tint the image like so: | ||
|
||
```dart | ||
final String assetName = 'assets/up_arrow.svg'; | ||
final Widget svgIcon = SvgPicture.asset( | ||
assetName, | ||
colorFilter: ColorFilter.mode(Colors.red, BlendMode.srcIn), | ||
semanticsLabel: 'A red up arrow' | ||
); | ||
``` | ||
|
||
The default placeholder is an empty box (`LimitedBox`) - although if a `height` | ||
or `width` is specified on the `SvgPicture`, a `SizedBox` will be used instead | ||
(which ensures better layout experience). There is currently no way to show an | ||
Error visually, however errors will get properly logged to the console in debug | ||
mode. | ||
|
||
You can also specify a placeholder widget. The placeholder will display during | ||
parsing/loading (normally only relevant for network access). | ||
|
||
```dart | ||
// Will print error messages to the console. | ||
final String assetName = 'assets/image_that_does_not_exist.svg'; | ||
final Widget svg = SvgPicture.asset( | ||
assetName, | ||
); | ||
final Widget networkSvg = SvgPicture.network( | ||
'https://site-that-takes-a-while.com/image.svg', | ||
semanticsLabel: 'A shark?!', | ||
placeholderBuilder: (BuildContext context) => Container( | ||
padding: const EdgeInsets.all(30.0), | ||
child: const CircularProgressIndicator()), | ||
); | ||
``` | ||
|
||
If you'd like to render the SVG to some other canvas, you can do something like: | ||
|
||
```dart | ||
import 'package:flutter_svg/flutter_svg.dart'; | ||
final String rawSvg = '''<svg ...>...</svg>'''; | ||
final PictureInfo pictureInfo = await vg.loadPicture(SvgStringLoader(rawSvg), null); | ||
// You can draw the picture to a canvas: | ||
canvas.drawPicture(pictureInfo.picture); | ||
// Or convert the picture to an image: | ||
final ui.Image image = pictureInfo.picture.toImage(...); | ||
pictureInfo.picture.dispose(); | ||
``` | ||
|
||
The `SvgPicture` helps to automate this logic, and it provides some convenience | ||
wrappers for getting assets from multiple sources. Unlike the `vector_graphics` | ||
package, this package _does not render the data to an `Image` at any point_. | ||
This carries a performance penalty for some common use cases, but also allows | ||
for more flexibility around scaling. | ||
|
||
## Precompiling and Optimizing SVGs | ||
|
||
The vector_graphics backend supports SVG compilation which produces a binary | ||
format that is faster to parse and can optimize SVGs to reduce the amount of | ||
clipping, masking, and overdraw. The SVG compilation is provided by | ||
[`package:vector_graphics_compiler`](https://pub.dev/packages/vector_graphics_compiler). | ||
|
||
```sh | ||
dart run vector_graphics_compiler -i assets/foo.svg -o assets/foo.svg.vec | ||
``` | ||
|
||
The output `foo.svg.vec` can be loaded using the default constructor of | ||
`SvgPicture`. | ||
|
||
```dart | ||
import 'package:flutter_svg/flutter_svg.dart'; | ||
import 'package:vector_graphics/vector_graphics.dart'; | ||
final Widget svg = SvgPicture( | ||
const AssetBytesLoader('assets/foo.svg.vec') | ||
); | ||
``` | ||
|
||
### Check SVG compatibility | ||
|
||
An SVG can be tested for compatibility with the vector graphics backend by | ||
running the compiler locally to see if any errors are thrown. | ||
|
||
```sh | ||
dart run vector_graphics_compiler -i $SVG_FILE -o $TEMPORARY_OUTPUT_TO_BE_DELETED --no-optimize-masks --no-optimize-clips --no-optimize-overdraw --no-tessellate | ||
``` | ||
|
||
## Recommended Adobe Illustrator SVG Configuration | ||
- In Styling: choose Presentation Attributes instead of Inline CSS because CSS is not fully supported. | ||
- In Images: choose Embded not Linked to other file to get a single svg with no dependency to other files. | ||
- In Objects IDs: choose layer names to add every layer name to svg tags or you can use minimal,it is optional. | ||
![Export configuration](https://user-images.githubusercontent.com/2842459/62599914-91de9c00-b8fe-11e9-8fb7-4af57d5100f7.png) | ||
|
||
## SVG sample attribution | ||
|
||
SVGs in `/assets/w3samples` pulled from [W3 sample files](https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/) | ||
|
||
SVGs in `/assets/deborah_ufw` provided by @deborah-ufw | ||
|
||
SVGs in `/assets/simple` are pulled from trivial examples or generated to test | ||
basic functionality - some of them come directly from the SVG 1.1 spec. Some | ||
have also come or been adapted from issues raised in this repository. | ||
|
||
SVGs in `/assets/wikimedia` are pulled from [Wikimedia Commons](https://commons.wikimedia.org/wiki/Main_Page) | ||
|
||
Android Drawables in `/assets/android_vd` are pulled from Android Documentation | ||
and examples. | ||
|
||
The Flutter Logo created based on the Flutter Logo Widget © Google. | ||
|
||
The Dart logo is from | ||
[dartlang.org](https://github.com/dart-lang/site-shared/blob/master/src/_assets/images/dart/logo%2Btext/horizontal/original.svg) | ||
|
||
SVGs in `/assets/noto-emoji` are from [Google i18n noto-emoji](https://github.com/googlei18n/noto-emoji), | ||
licensed under the Apache license. | ||
|
||
Please submit SVGs that can't render properly (e.g. that don't render here the | ||
way they do in chrome), as long as they're not using anything "probably out of | ||
scope" (above). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.DS_Store | ||
.dart_tool/ | ||
|
||
.packages | ||
.pub/ | ||
|
||
build/ | ||
|
||
.flutter-plugins | ||
|
||
flutter_export_environment.sh | ||
|
||
flutter_*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled. | ||
|
||
version: | ||
revision: 1725a26e2950a3d98e2af8c98759e11a47b2f90e | ||
channel: master | ||
|
||
project_type: app | ||
|
||
# Tracks metadata for the flutter migrate command | ||
migration: | ||
platforms: | ||
- platform: root | ||
create_revision: 1725a26e2950a3d98e2af8c98759e11a47b2f90e | ||
base_revision: 1725a26e2950a3d98e2af8c98759e11a47b2f90e | ||
- platform: macos | ||
create_revision: 1725a26e2950a3d98e2af8c98759e11a47b2f90e | ||
base_revision: 1725a26e2950a3d98e2af8c98759e11a47b2f90e | ||
|
||
# User provided section | ||
|
||
# List of Local paths (relative to this file) that should be | ||
# ignored by the migrate tool. | ||
# | ||
# Files that are not part of the templates will be ignored by default. | ||
unmanaged_files: | ||
- 'lib/main.dart' | ||
- 'ios/Runner.xcodeproj/project.pbxproj' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# example | ||
|
||
A new Flutter project. | ||
|
||
## Getting Started | ||
|
||
For help getting started with Flutter, view our online | ||
[documentation](https://flutter.io/). | ||
|
||
## Benchmarking | ||
|
||
`flutter drive --profile --endless-trace-buffer --target test_driver/bench.dart` |
29 changes: 29 additions & 0 deletions
29
third_party/packages/flutter_svg/example/analysis_options.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This file configures the analyzer, which statically analyzes Dart code to | ||
# check for errors, warnings, and lints. | ||
# | ||
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled | ||
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be | ||
# invoked from the command line by running `flutter analyze`. | ||
|
||
# The following line activates a set of recommended lints for Flutter apps, | ||
# packages, and plugins designed to encourage good coding practices. | ||
include: package:flutter_lints/flutter.yaml | ||
|
||
linter: | ||
# The lint rules applied to this project can be customized in the | ||
# section below to disable rules from the `package:flutter_lints/flutter.yaml` | ||
# included above or to enable additional rules. A list of all available lints | ||
# and their documentation is published at | ||
# https://dart-lang.github.io/linter/lints/index.html. | ||
# | ||
# Instead of disabling a lint rule for the entire project in the | ||
# section below, it can also be suppressed for a single line of code | ||
# or a specific dart file by using the `// ignore: name_of_lint` and | ||
# `// ignore_for_file: name_of_lint` syntax on the line or in the file | ||
# producing the lint. | ||
rules: | ||
# avoid_print: false # Uncomment to disable the `avoid_print` rule | ||
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options |
11 changes: 11 additions & 0 deletions
11
third_party/packages/flutter_svg/example/android/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
gradle-wrapper.jar | ||
/.gradle | ||
/captures/ | ||
/gradlew | ||
/gradlew.bat | ||
/local.properties | ||
GeneratedPluginRegistrant.java | ||
|
||
# Remember to never publicly share your keystore. | ||
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app | ||
key.properties |
59 changes: 59 additions & 0 deletions
59
third_party/packages/flutter_svg/example/android/app/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
def localProperties = new Properties() | ||
def localPropertiesFile = rootProject.file('local.properties') | ||
if (localPropertiesFile.exists()) { | ||
localPropertiesFile.withReader('UTF-8') { reader -> | ||
localProperties.load(reader) | ||
} | ||
} | ||
|
||
def flutterRoot = localProperties.getProperty('flutter.sdk') | ||
if (flutterRoot == null) { | ||
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") | ||
} | ||
|
||
def flutterVersionCode = localProperties.getProperty('flutter.versionCode') | ||
if (flutterVersionCode == null) { | ||
flutterVersionCode = '1' | ||
} | ||
|
||
def flutterVersionName = localProperties.getProperty('flutter.versionName') | ||
if (flutterVersionName == null) { | ||
flutterVersionName = '1.0' | ||
} | ||
|
||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" | ||
|
||
android { | ||
compileSdkVersion 31 | ||
|
||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
|
||
defaultConfig { | ||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). | ||
applicationId "com.example.example" | ||
minSdkVersion 16 | ||
targetSdkVersion 30 | ||
versionCode flutterVersionCode.toInteger() | ||
versionName flutterVersionName | ||
} | ||
|
||
buildTypes { | ||
release { | ||
// TODO: Add your own signing config for the release build. | ||
// Signing with the debug keys for now, so `flutter run --release` works. | ||
signingConfig signingConfigs.debug | ||
} | ||
} | ||
} | ||
|
||
flutter { | ||
source '../..' | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
} |
7 changes: 7 additions & 0 deletions
7
third_party/packages/flutter_svg/example/android/app/src/debug/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.example"> | ||
<!-- Flutter needs it to communicate with the running application | ||
to allow setting breakpoints, to provide hot reload, etc. | ||
--> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
</manifest> |
32 changes: 32 additions & 0 deletions
32
third_party/packages/flutter_svg/example/android/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.example"> | ||
<application | ||
android:label="example" | ||
android:icon="@mipmap/ic_launcher"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:launchMode="singleTop" | ||
android:theme="@style/LaunchTheme" | ||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" | ||
android:hardwareAccelerated="true" | ||
android:windowSoftInputMode="adjustResize"> | ||
<!-- Specifies an Android theme to apply to this Activity as soon as | ||
the Android process has started. This theme is visible to the user | ||
while the Flutter UI initializes. After that, this theme continues | ||
to determine the Window background behind the Flutter UI. --> | ||
<meta-data | ||
android:name="io.flutter.embedding.android.NormalTheme" | ||
android:resource="@style/NormalTheme" | ||
/> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<!-- Don't delete the meta-data below. | ||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> | ||
<meta-data | ||
android:name="flutterEmbedding" | ||
android:value="2" /> | ||
</application> | ||
</manifest> |
6 changes: 6 additions & 0 deletions
6
...kages/flutter_svg/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.example.example | ||
|
||
import io.flutter.embedding.android.FlutterActivity | ||
|
||
class MainActivity: FlutterActivity() { | ||
} |
12 changes: 12 additions & 0 deletions
12
.../packages/flutter_svg/example/android/app/src/main/res/drawable-v21/launch_background.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Modify this file to customize your launch splash screen --> | ||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:drawable="?android:colorBackground" /> | ||
|
||
<!-- You can insert your own image assets here --> | ||
<!-- <item> | ||
<bitmap | ||
android:gravity="center" | ||
android:src="@mipmap/launch_image" /> | ||
</item> --> | ||
</layer-list> |
Oops, something went wrong.