Skip to content

Commit a0da1f2

Browse files
committed
Support for flutter-go-desktop
1 parent 47c2b81 commit a0da1f2

19 files changed

+560
-3
lines changed

example/go/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
.last_goflutter_check

example/go/assets/icon.png

3.95 KB
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
// DO NOT EDIT, this file is generated by hover at compile-time for the flutter_image_compress plugin.
4+
5+
import (
6+
flutter "github.com/go-flutter-desktop/go-flutter"
7+
flutter_image_compress "github.com/openflutter/flutter_image_compress/go"
8+
)
9+
10+
func init() {
11+
// Only the init function can be tweaked by plugin maker.
12+
options = append(options, flutter.AddPlugin(&flutter_image_compress.FlutterImageCompressPlugin{}))
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
// DO NOT EDIT, this file is generated by hover at compile-time for the path_provider plugin.
4+
5+
import (
6+
flutter "github.com/go-flutter-desktop/go-flutter"
7+
path_provider "github.com/go-flutter-desktop/plugins/path_provider"
8+
)
9+
10+
func init() {
11+
// Only the init function can be tweaked by plugin maker.
12+
options = append(options, flutter.AddPlugin(&path_provider.PathProviderPlugin{
13+
VendorName: flutter.ProjectOrganizationName,
14+
ApplicationName: flutter.ProjectName,
15+
}))
16+
}

example/go/cmd/main.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"image"
6+
_ "image/png"
7+
"os"
8+
"path/filepath"
9+
"strings"
10+
11+
"github.com/go-flutter-desktop/go-flutter"
12+
"github.com/pkg/errors"
13+
)
14+
15+
// vmArguments may be set by hover at compile-time
16+
var vmArguments string
17+
18+
func main() {
19+
// DO NOT EDIT, add options in options.go
20+
mainOptions := []flutter.Option{
21+
flutter.OptionVMArguments(strings.Split(vmArguments, ";")),
22+
flutter.WindowIcon(iconProvider),
23+
}
24+
err := flutter.Run(append(options, mainOptions...)...)
25+
if err != nil {
26+
fmt.Println(err)
27+
os.Exit(1)
28+
}
29+
}
30+
31+
func iconProvider() ([]image.Image, error) {
32+
execPath, err := os.Executable()
33+
if err != nil {
34+
return nil, errors.Wrap(err, "failed to resolve executable path")
35+
}
36+
execPath, err = filepath.EvalSymlinks(execPath)
37+
if err != nil {
38+
return nil, errors.Wrap(err, "failed to eval symlinks for executable path")
39+
}
40+
imgFile, err := os.Open(filepath.Join(filepath.Dir(execPath), "assets", "icon.png"))
41+
if err != nil {
42+
return nil, errors.Wrap(err, "failed to open assets/icon.png")
43+
}
44+
img, _, err := image.Decode(imgFile)
45+
if err != nil {
46+
return nil, errors.Wrap(err, "failed to decode image")
47+
}
48+
return []image.Image{img}, nil
49+
}

example/go/cmd/options.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import (
4+
"github.com/go-flutter-desktop/go-flutter"
5+
)
6+
7+
var options = []flutter.Option{
8+
flutter.WindowInitialDimensions(800, 1280),
9+
}

example/go/go.mod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module flutter_image_compress_example/go
2+
3+
go 1.13
4+
5+
require (
6+
github.com/chai2010/webp v1.1.0 // indirect
7+
github.com/disintegration/imaging v1.6.2 // indirect
8+
github.com/go-flutter-desktop/go-flutter v0.40.1
9+
github.com/go-flutter-desktop/plugins/path_provider v0.4.0
10+
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
11+
github.com/openflutter/flutter_image_compress/go v0.0.0-00010101000000-000000000000
12+
github.com/pkg/errors v0.9.1
13+
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 // indirect
14+
)
15+
16+
replace github.com/openflutter/flutter_image_compress/go => /Users/caijinglong/Documents/GitHub/flutter_image_compress/go

example/go/go.sum

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
github.com/Xuanwo/go-locale v0.2.0 h1:1N8SGG2VNpLl6VVa8ueZm3Nm+dxvk8ffY9aviKHl4IE=
2+
github.com/Xuanwo/go-locale v0.2.0/go.mod h1:6qbT9M726OJgyiGZro2YwPmx63wQzlH+VvtjJWQoftw=
3+
github.com/adrg/xdg v0.2.1 h1:VSVdnH7cQ7V+B33qSJHTCRlNgra1607Q8PzEmnvb2Ic=
4+
github.com/adrg/xdg v0.2.1/go.mod h1:ZuOshBmzV4Ta+s23hdfFZnBsdzmoR3US0d7ErpqSbTQ=
5+
github.com/chai2010/webp v1.1.0 h1:4Ei0/BRroMF9FaXDG2e4OxwFcuW2vcXd+A6tyqTJUQQ=
6+
github.com/chai2010/webp v1.1.0/go.mod h1:LP12PG5IFmLGHUU26tBiCBKnghxx3toZFwDjOYvd3Ow=
7+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10+
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
11+
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
12+
github.com/go-flutter-desktop/go-flutter v0.37.0/go.mod h1:8tjt3yZ3lTNLqgzWeH90f1uhCR9BL68LFoiy/n0aw/w=
13+
github.com/go-flutter-desktop/go-flutter v0.40.1 h1:4GC+9sc4jLxFoqLcHIGBNHdcF99ABC30g2q9iIQ+100=
14+
github.com/go-flutter-desktop/go-flutter v0.40.1/go.mod h1:VNXgUO61Nxa9y/5jHQJFFuWVK9oNQF56MPKPUgQXwlU=
15+
github.com/go-flutter-desktop/plugins v0.0.0-20200502124433-338c83f03c4f h1:fxuMAOcdCv/8KXQOF2De2Jkvrj8hshM4dnKU3VpRkKg=
16+
github.com/go-flutter-desktop/plugins/path_provider v0.4.0 h1:LhYqOJjwuRjf9MzmbvkejCtLqrEEeBzrsCWkVONG6uw=
17+
github.com/go-flutter-desktop/plugins/path_provider v0.4.0/go.mod h1:e0aUP0dqcGaw5EZpCYzlK7M/T6X0ueWYJXImrE25vb4=
18+
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
19+
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
20+
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
21+
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200420212212-258d9bec320e h1:8ywu4ELC/6owgOZlZx75CyYS5AYwUT2L+hzPModKvag=
22+
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200420212212-258d9bec320e/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
23+
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
24+
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
25+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
26+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
27+
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
28+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
29+
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
30+
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
31+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
32+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
33+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
34+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
35+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
36+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
37+
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
38+
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
39+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
40+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
41+
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
42+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
43+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
44+
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
45+
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw=
46+
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
47+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
48+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
49+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
50+
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
51+
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
52+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
53+
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
54+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
55+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
56+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
57+
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
58+
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

example/go/hover.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#application-name: "flutter_image_compress_example" # Uncomment to modify this value.
2+
#executable-name: "flutter_image_compress_example" # Uncomment to modify this value. Only lowercase a-z, numbers, underscores and no spaces
3+
#package-name: "flutterimagecompressexample" # Uncomment to modify this value. Only lowercase a-z, numbers and no underscores or spaces
4+
license: "" # MANDATORY: Fill in your SPDX license name: https://spdx.org/licenses
5+
target: lib/main_desktop.dart
6+
branch: "" # Change to "@latest" to download the latest go-flutter version on every build
7+
# cache-path: "/home/YOURUSERNAME/.cache/" # https://github.com/go-flutter-desktop/go-flutter/issues/184
8+
# opengl: "none" # Uncomment this line if you have trouble with your OpenGL driver (https://github.com/go-flutter-desktop/go-flutter/issues/272)
9+
docker: false
10+
engine-version: "" # change to a engine version commit

example/lib/main.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class _MyAppState extends State<MyApp> {
134134
final dir = await path_provider.getTemporaryDirectory();
135135
print('dir = $dir');
136136

137-
File file = File("${dir.absolute.path}/test.png");
137+
File file = createFile("${dir.absolute.path}/test.png");
138138
file.writeAsBytesSync(data.buffer.asUint8List());
139139

140140
List<int> list = await testCompressFile(file);
@@ -143,6 +143,15 @@ class _MyAppState extends State<MyApp> {
143143
setState(() {});
144144
}
145145

146+
File createFile(String path) {
147+
final file = File(path);
148+
if (!file.existsSync()) {
149+
file.createSync(recursive: true);
150+
}
151+
152+
return file;
153+
}
154+
146155
Future<String> getExampleFilePath() async {
147156
final img = AssetImage("img/img.jpg");
148157
print("pre compress");
@@ -152,7 +161,8 @@ class _MyAppState extends State<MyApp> {
152161
final ByteData data = await key.bundle.load(key.name);
153162
final dir = await path_provider.getTemporaryDirectory();
154163

155-
File file = File("${dir.absolute.path}/test.png");
164+
File file = createFile("${dir.absolute.path}/test.png");
165+
file.createSync(recursive: true);
156166
file.writeAsBytesSync(data.buffer.asUint8List());
157167
return file.absolute.path;
158168
}
@@ -166,7 +176,7 @@ class _MyAppState extends State<MyApp> {
166176
final ByteData data = await key.bundle.load(key.name);
167177
final dir = await path_provider.getTemporaryDirectory();
168178

169-
File file = File("${dir.absolute.path}/test.png");
179+
File file = createFile("${dir.absolute.path}/test.png");
170180
file.writeAsBytesSync(data.buffer.asUint8List());
171181

172182
final targetPath = dir.absolute.path + "/temp.jpg";
@@ -240,6 +250,7 @@ class _MyAppState extends State<MyApp> {
240250
minWidth: 1080,
241251
quality: 96,
242252
rotate: 270,
253+
format: CompressFormat.webp,
243254
);
244255
print(list.length);
245256
print(result.length);

0 commit comments

Comments
 (0)