diff --git a/example/edit_icon/lib/main.dart b/example/edit_icon/lib/main.dart index b20bbdf..b98d652 100644 --- a/example/edit_icon/lib/main.dart +++ b/example/edit_icon/lib/main.dart @@ -5,7 +5,9 @@ import 'dart:io'; import 'package:betrayal/betrayal.dart'; import 'package:edit_icon/view/view.dart'; import 'package:file_picker/file_picker.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:image/image.dart' as img; void main() { runApp(const MyApp()); @@ -104,10 +106,27 @@ class _HomeScreenState extends State { FilePickerResult? result = await FilePicker.platform.pickFiles( type: FileType.custom, allowedExtensions: const ["ico", "png"]); if (result == null) return; - final path = result.files.first.path!; + final file = result.files.first; + final path = file.path!; + + late TrayIconImageDelegate iconSource; + switch (file.extension) { + case "ico": + iconSource = TrayIconImageDelegate.fromPath(path: path); + break; + case "png": + var resized = await compute((String path) { + var org = img.decodePng(File(path).readAsBytesSync()); + var resized = img.copyResizeCropSquare(org!, 32); + return resized.getBytes().buffer; + }, path); + + iconSource = TrayIconImageDelegate.fromBytes(resized); + break; + } + _delegate.add(MyData( - delegate: TrayIconImageDelegate.fromWinIcon(WinIcon.application), - builder: (_) => Image.file(File(path)))); + delegate: iconSource, builder: (_) => Image.file(File(path)))); }, )); } diff --git a/example/edit_icon/lib/view/element_selector/selector.dart b/example/edit_icon/lib/view/element_selector/selector.dart index cffb3d6..39b6d93 100644 --- a/example/edit_icon/lib/view/element_selector/selector.dart +++ b/example/edit_icon/lib/view/element_selector/selector.dart @@ -123,7 +123,7 @@ class _ElementSelectorState extends State initialPage: _currentPage, viewportFraction: widget.dimension / (widget.axis == Axis.vertical - ? MediaQuery.of(context).size.height + ? (MediaQuery.of(context).size.height) : MediaQuery.of(context).size.width)); return PageView.builder( allowImplicitScrolling: true, @@ -145,7 +145,10 @@ class _ElementSelectorState extends State tooltip: widget.addTooltip, iconSize: widget.dimension * 0.5, icon: Icon(Icons.add, - color: Theme.of(context).colorScheme.onBackground), + color: Theme.of(context) + .colorScheme + .onBackground + .withOpacity(0.3)), onPressed: () async { await widget.onAddPressed!(); }, diff --git a/example/edit_icon/pubspec.lock b/example/edit_icon/pubspec.lock index 6259a66..37abf4a 100644 --- a/example/edit_icon/pubspec.lock +++ b/example/edit_icon/pubspec.lock @@ -1,6 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "3.3.0" async: dependency: transitive description: @@ -50,6 +57,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" fake_async: dependency: transitive description: @@ -100,6 +114,13 @@ packages: description: flutter source: sdk version: "0.0.0" + image: + dependency: "direct main" + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.3" js: dependency: transitive description: @@ -142,6 +163,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "4.4.0" plugin_platform_interface: dependency: transitive description: @@ -217,6 +245,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.5.0" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "5.3.1" sdks: dart: ">=2.16.2 <3.0.0" flutter: ">=2.5.0" diff --git a/example/edit_icon/pubspec.yaml b/example/edit_icon/pubspec.yaml index 26f2bd4..5e9c082 100644 --- a/example/edit_icon/pubspec.yaml +++ b/example/edit_icon/pubspec.yaml @@ -18,6 +18,7 @@ dependencies: # the parent directory to use the current plugin's version. path: ../../ file_picker: ^4.5.1 + image: ^3.1.3 dev_dependencies: flutter_test: