Skip to content

Commit

Permalink
feat(example): set loaded image as icon image
Browse files Browse the repository at this point in the history
  • Loading branch information
benthillerkus committed Apr 2, 2022
1 parent 50ee78e commit 20f3fcd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
25 changes: 22 additions & 3 deletions example/edit_icon/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -104,10 +106,27 @@ class _HomeScreenState extends State<HomeScreen> {
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))));
},
));
}
Expand Down
7 changes: 5 additions & 2 deletions example/edit_icon/lib/view/element_selector/selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class _ElementSelectorState extends State<ElementSelector>
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,
Expand All @@ -145,7 +145,10 @@ class _ElementSelectorState extends State<ElementSelector>
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!();
},
Expand Down
35 changes: 35 additions & 0 deletions example/edit_icon/pubspec.lock
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
1 change: 1 addition & 0 deletions example/edit_icon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 20f3fcd

Please sign in to comment.