Skip to content

Commit 8c4d34f

Browse files
committed
initial commit
0 parents  commit 8c4d34f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+58214
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.DS_Store
2+
deploy/*
3+
vendor/*
4+
rcc*
5+
moc*
6+
*.qmlc
7+
8+
build/*
9+
.packages
10+
.dart_tool
11+
pubspec.lock
12+
13+
*flutter_engine.*
14+
FlutterEmbedder.framework

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[BINARIES](https://github.com/therecipe/flutter/releases/tag/v0.0.0)
2+
3+
---
4+
5+
Introduction
6+
------------
7+
8+
TBD
9+
10+
Status
11+
------
12+
13+
Almost all Qt functions and classes are accessible from Dart and you should be able to find everything you need to build fully featured Qt applications in Dart, the feature-set shown represents only a small portion of all the features available.
14+
15+
However this is still very much experimental, and there are memory leaks and enums aren't support yet.
16+
17+
Another caveat is that the flutter embedder currently only supports debug builds and the interop api isn't working on windows yet.
18+
It's also planned to make the custom flutter embedder optional and support plain dart projects as well.
19+
20+
Also, the interop api isn't frozen yet and might change in the future.
21+
22+
Info
23+
----
24+
25+
For general information about `therecipe/qt`, checkout: https://github.com/therecipe/qt
26+
27+
The Qt API Docs can be found here: https://doc.qt.io/qt-5/classes.html
28+
29+
If you have questions, join our Slack channel [#qt-binding](https://gophers.slack.com/messages/qt-binding/details) ([invite yourself here](https://invite.slack.golangbridge.org)\)
30+
31+
Usage
32+
-----
33+
34+
Setup `therecipe/qt` and install Flutter: https://flutter.dev/docs/get-started/install
35+
After adding the `flutter/bin` dir to your PATH, you can use `qtdeploy` to build the showcase.
36+
If you just want to rebuild the flutter code, you can use `flutter build bundle`.
37+
To enabled hot reloading, you can use something like: `flutter attach --debug-uri=http://127.0.0.1:60123/xyzxyzxyz/`

deploy.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
set -ev
3+
4+
OPWD=$PWD
5+
NAME=flutter
6+
7+
qtdeploy -docker build linux && rm -rf rcc* moc* vendor && git clean -f && git reset --hard && docker rmi therecipe/qt:linux
8+
cd $OPWD/deploy/linux && zip -q -9 -r ../${NAME}_linux_amd64_shared.zip * && cd $OPWD && rm -rf $OPWD/deploy/linux
9+
10+
qtdeploy -docker build linux_static && rm -rf rcc* moc* vendor && git clean -f && git reset --hard && docker rmi therecipe/qt:linux_static
11+
cd $OPWD/deploy/linux && zip -q -9 -r ../${NAME}_linux_amd64.zip * && cd $OPWD && rm -rf $OPWD/deploy/linux
12+
13+
14+
qtdeploy -docker build windows_64_shared_wine && rm -rf rcc* moc* vendor && git clean -f && git reset --hard && docker rmi therecipe/qt:windows_64_shared_wine
15+
cd $OPWD/deploy/windows && zip -q -9 -r ../${NAME}_windows_amd64_shared.zip * && cd $OPWD && rm -rf $OPWD/deploy/windows
16+
17+
18+
cd $(go env GOPATH)/src/github.com/therecipe/qt/internal/docker/darwin && ./build.sh && cd $OPWD
19+
qtdeploy -docker build darwin && rm -rf rcc* moc* vendor && git clean -f && git reset --hard && docker rmi therecipe/qt:darwin
20+
cd $OPWD/deploy/darwin && zip -q -9 -r ../${NAME}_darwin_amd64_shared.zip * && cd $OPWD && rm -rf $OPWD/deploy/darwin
21+
22+
cd $(go env GOPATH)/src/github.com/therecipe/qt/internal/docker/darwin && ./build_static.sh && cd $OPWD
23+
qtdeploy -docker build darwin_static && rm -rf rcc* moc* vendor && git clean -f && git reset --hard && docker rmi therecipe/qt:darwin_static
24+
cd $OPWD/deploy/darwin && zip -q -9 -r ../${NAME}_darwin_amd64.zip * && cd $OPWD && rm -rf $OPWD/deploy/darwin

lib/main.dart

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import 'package:flutter/material.dart';
2+
import 'dart:io';
3+
4+
/*
5+
this is needed atm to let qtdeploy/qtminimal know that this file needs to be analysed
6+
7+
import (
8+
"github.com/therecipe/qt/core"
9+
"github.com/therecipe/qt/quick"
10+
"github.com/therecipe/qt/quickcontrols2"
11+
)
12+
*/
13+
14+
import 'qt/interop.dart' as interop;
15+
import 'qt/core.dart' as core;
16+
import 'qt/quick.dart' as quick;
17+
import 'qt/quickcontrols2.dart' as quickcontrols2;
18+
19+
final interopEngine = (!Platform.isWindows) ? interop.PseudoQJSEngine_qjsEngine(null) : null;
20+
final quickWidget = (!Platform.isWindows) ? quick.NewQQuickWidget(null) : null;
21+
22+
void main() {
23+
24+
if (!Platform.isWindows) {
25+
interopEngine.GlobalObject().SetProperty("dartFunction", interopEngine.NewGoType((String s) { print(s); }));
26+
27+
// setup qml widget
28+
29+
quickcontrols2.QQuickStyle_SetStyle("Material");
30+
31+
quickWidget.Engine().GlobalObject().SetProperty("dartFunction", quickWidget.Engine().NewGoType((String s) { print(s); }));
32+
quickWidget.Engine().GlobalObject().SetProperty("qml", quickWidget.Engine().NewObject()); //create an empty object here, so we can write to it later from withing Qml since we can't directly add properties to the globalObject from within qml
33+
quickWidget.SetMinimumSize(core.NewQSize2(400, 300));
34+
quickWidget.SetResizeMode(1); //TODO: quick.QQuickWidget__SizeRootObjectToView
35+
quickWidget.SetSource(core.NewQUrl3("qrc:/qml/main.qml", 0));
36+
37+
// call into go and let it finish the layout setup
38+
39+
interopEngine.GlobalObject().SetProperty("quickWidget", interopEngine.NewGoType(quickWidget));
40+
interopEngine.GlobalObject().Property("goSetupFunction").Call(null);
41+
}
42+
43+
runApp(MyApp());
44+
}
45+
46+
/// This Widget is the main application widget.
47+
class MyApp extends StatelessWidget {
48+
static const String _title = 'Dart-Go-Qml Interop';
49+
50+
@override
51+
Widget build(BuildContext context) {
52+
return MaterialApp(
53+
title: _title,
54+
home: Scaffold(
55+
appBar: AppBar(title: const Text(_title)),
56+
body: MyStatelessWidget(),
57+
),
58+
);
59+
}
60+
}
61+
62+
/// This is the stateless widget that the main application instantiates.
63+
class MyStatelessWidget extends StatelessWidget {
64+
MyStatelessWidget({Key key}) : super(key: key);
65+
66+
@override
67+
Widget build(BuildContext context) {
68+
return Center(
69+
child: Column(
70+
mainAxisSize: MainAxisSize.min,
71+
children: <Widget>[
72+
RaisedButton(
73+
onPressed: () {
74+
if (!Platform.isWindows) {
75+
interopEngine.GlobalObject().Property("goFunction").Call([interopEngine.NewGoType("Hello from Dart")]);
76+
}
77+
},
78+
child: const Text('Dart calls Go', style: TextStyle(fontSize: 20)),
79+
),
80+
const SizedBox(height: 30),
81+
RaisedButton(
82+
onPressed: () {
83+
if (!Platform.isWindows) {
84+
quickWidget.Engine().GlobalObject().Property("qml").Property("qmlFunction").Call([quickWidget.Engine().NewGoType("Hello from Dart")]);
85+
}
86+
},
87+
child: const Text('Dart calls Qml', style: TextStyle(fontSize: 20)),
88+
),
89+
],
90+
),
91+
);
92+
}
93+
}

0 commit comments

Comments
 (0)