Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/vector_graphics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT

* Updates minimum supported SDK version to Flutter 3.32/Dart 3.8.
* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.
* Make workspace for example.

## 1.1.19

Expand Down
32 changes: 29 additions & 3 deletions packages/vector_graphics/lib/src/loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: experimental_member_use

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart' show RecordUse, mustBeConst;

/// An interface that can be implemented to support decoding vector graphic
/// binary assets from different byte sources.
Expand Down Expand Up @@ -36,6 +39,27 @@ abstract class BytesLoader {
Object cacheKey(BuildContext? context) => this;
}

/// The magic prefix to prevent accidental non-const loading.
///
/// Must be the same as when storing the asset in build.dart.
///
/// TODO: move to a common location.
const magicPrefix = 'svg1234:';

/// Loads vector graphics data from an asset bundle.
@RecordUse()
class ConstAssetBytesLoader extends AssetBytesLoader {
///
const ConstAssetBytesLoader(
@mustBeConst super.assetName, {
super.packageName,
super.assetBundle,
});

@override
String get assetName => magicPrefix + super.assetName;
}

/// Loads vector graphics data from an asset bundle.
///
/// This loader does not cache bytes by default. The Flutter framework
Expand Down Expand Up @@ -73,9 +97,11 @@ class AssetBytesLoader extends BytesLoader {

@override
Future<ByteData> loadBytes(BuildContext? context) {
return _resolveBundle(context).load(
packageName == null ? assetName : 'packages/$packageName/$assetName',
);
final String key = packageName == null
? assetName
: 'packages/$packageName/$assetName';
print('load $key');
return _resolveBundle(context).load(key);
}

@override
Expand Down
1 change: 1 addition & 0 deletions packages/vector_graphics/lib/vector_graphics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export 'src/vector_graphics.dart'
show
AssetBytesLoader,
BytesLoader,
ConstAssetBytesLoader,
NetworkBytesLoader,
PictureInfo,
VectorGraphic,
Expand Down
5 changes: 3 additions & 2 deletions packages/vector_graphics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+
version: 1.1.19

environment:
sdk: ^3.8.0
flutter: ">=3.32.0"
sdk: ^3.10.0
flutter: ">=3.38.0"

dependencies:
flutter:
sdk: flutter
http: ^1.0.0
meta: ^1.17.0
vector_graphics_codec: ^1.1.11+1

dev_dependencies:
Expand Down
3 changes: 2 additions & 1 deletion packages/vector_graphics_compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT

* Updates minimum supported SDK version to Flutter 3.35/Dart 3.9.
* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.
* Add build hook helper to allow for transforming assets through hooks.

## 1.1.19

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import 'dart:io';
import 'package:args/args.dart';
import 'package:path/path.dart' as p;
import 'package:vector_graphics_compiler/src/svg/colors.dart';
import 'package:vector_graphics_compiler/src/util/isolate_processor.dart';
import 'package:vector_graphics_compiler/vector_graphics_compiler.dart';

import 'util/isolate_processor.dart';

final ArgParser argParser = ArgParser()
..addOption(
'current-color',
Expand Down Expand Up @@ -152,7 +151,7 @@ Future<void> main(List<String> args) async {
}
validateOptions(results);

final pairs = <Pair>[];
final pairs = <IOPair>[];
if (results.wasParsed('input-dir')) {
final directory = Directory(results['input-dir'] as String);
if (!directory.existsSync()) {
Expand All @@ -177,13 +176,13 @@ Future<void> main(List<String> args) async {
outputPath = p.join(outDir.path, '${p.basename(file.path)}.vec');
}

pairs.add(Pair(file.path, outputPath));
pairs.add(IOPair(file.path, outputPath));
}
} else {
final inputFilePath = results['input'] as String;
final String outputFilePath =
results['output'] as String? ?? '$inputFilePath.vec';
pairs.add(Pair(inputFilePath, outputFilePath));
pairs.add(IOPair(inputFilePath, outputFilePath));
}

final maskingOptimizerEnabled = results['optimize-masks'] == true;
Expand Down
45 changes: 45 additions & 0 deletions packages/vector_graphics_compiler/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/
/coverage/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
30 changes: 30 additions & 0 deletions packages/vector_graphics_compiler/example/.metadata
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 and should not be manually edited.

version:
revision: "260e8f022510f454d23ee9f563a5092ae4e64289"
channel: "[user-branch]"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 260e8f022510f454d23ee9f563a5092ae4e64289
base_revision: 260e8f022510f454d23ee9f563a5092ae4e64289
- platform: web
create_revision: 260e8f022510f454d23ee9f563a5092ae4e64289
base_revision: 260e8f022510f454d23ee9f563a5092ae4e64289

# 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'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
buildFlags:
_pluginToolsConfigGlobalKey:
- "--no-tree-shake-icons"
- "--dart-define=buildmode=testing"
configs:
- "--enable-dart-data-assets"
8 changes: 8 additions & 0 deletions packages/vector_graphics_compiler/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Vector Graphics Compiler - Build Hooks Example

A Flutter showcase for how to replace asset transformers with hooks.

To run execute:
```bash
flutter run
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions packages/vector_graphics_compiler/example/hook/build.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:hooks/hooks.dart';
import 'package:vector_graphics_compiler/build.dart';

void main(List<String> args) {
build(args, (BuildInput input, BuildOutputBuilder output) async {
await addSvg(
input,
output,
file: 'assets/example.svg',
treeshakeable: true,
);
});
}
34 changes: 34 additions & 0 deletions packages/vector_graphics_compiler/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:vector_graphics/vector_graphics.dart';

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

/// The main example app widget.
class MyApp extends StatelessWidget {
/// Creates a new [MyApp].
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Vector Graphics Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: const Scaffold(
body: Center(
child: VectorGraphic(
loader: ConstAssetBytesLoader(
'assets/example.svg',
packageName: 'example',
),
),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flutter/ephemeral
Loading
Loading