-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[pigeon] Enable example app build in CI #8119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import ExampleHostApi | |
import FlutterError | ||
import MessageData | ||
import MessageFlutterApi | ||
import androidx.annotation.NonNull | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
|
@@ -37,22 +36,21 @@ private class PigeonApiImplementation : ExampleHostApi { | |
// #enddocregion kotlin-class | ||
|
||
// #docregion kotlin-class-flutter | ||
private class PigeonFlutterApi { | ||
|
||
private class PigeonFlutterApi(binding: FlutterPlugin.FlutterPluginBinding) { | ||
var flutterApi: MessageFlutterApi? = null | ||
|
||
constructor(binding: FlutterPlugin.FlutterPluginBinding) { | ||
flutterApi = MessageFlutterApi(binding.getBinaryMessenger()) | ||
init { | ||
flutterApi = MessageFlutterApi(binding.binaryMessenger) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a Kotlin style suggestion from AS. |
||
} | ||
|
||
fun callFlutterMethod(aString: String, callback: (Result<String>) -> Unit) { | ||
flutterApi!!.flutterMethod(aString) { echo -> callback(Result.success(echo)) } | ||
flutterApi!!.flutterMethod(aString) { echo -> callback(echo) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per discussion in another PR, this code is wrong, and we just hadn't noticed because it wasn't building. |
||
} | ||
} | ||
// #enddocregion kotlin-class-flutter | ||
|
||
class MainActivity : FlutterActivity() { | ||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | ||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AS flagged that we shouldn't be using nullability annotations in Kotlin. |
||
super.configureFlutterEngine(flutterEngine) | ||
|
||
val api = PigeonApiImplementation() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,16 +37,16 @@ private class PigeonFlutterApi { | |
} | ||
|
||
func callFlutterMethod( | ||
aString aStringArg: String?, completion: @escaping (Result<String, Error>) -> Void | ||
aString aStringArg: String?, completion: @escaping (Result<String, PigeonError>) -> Void | ||
) { | ||
flutterAPI.flutterMethod(aString: aStringArg) { | ||
completion(.success($0)) | ||
completion($0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As with the Kotlin file, this was wrong and didn't compile. |
||
} | ||
} | ||
} | ||
// #enddocregion swift-class-flutter | ||
|
||
@UIApplicationMain | ||
@main | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a Flutter tool auto-migration; I didn't see any reason to undo it. |
||
@objc class AppDelegate: FlutterAppDelegate { | ||
override func application( | ||
_ application: UIApplication, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,21 @@ | |
|
||
#include "flutter_window.h" | ||
|
||
#include <flutter/binary_messenger.h> | ||
|
||
#include <memory> | ||
#include <optional> | ||
|
||
#include "flutter/generated_plugin_registrant.h" | ||
#include "messages.g.h" | ||
|
||
namespace { | ||
using pigeon_example::Code; | ||
using pigeon_example::ErrorOr; | ||
using pigeon_example::ExampleHostApi; | ||
using pigeon_example::FlutterError; | ||
using pigeon_example::MessageData; | ||
using pigeon_example::MessageFlutterApi; | ||
|
||
// #docregion cpp-class | ||
class PigeonApiImplementation : public ExampleHostApi { | ||
|
@@ -29,14 +35,34 @@ class PigeonApiImplementation : public ExampleHostApi { | |
} | ||
void SendMessage(const MessageData& message, | ||
std::function<void(ErrorOr<bool> reply)> result) { | ||
if (message.code == Code.kOne) { | ||
if (message.code() == Code::kOne) { | ||
result(FlutterError("code", "message", "details")); | ||
return; | ||
} | ||
result(true); | ||
} | ||
}; | ||
// #enddocregion cpp-class | ||
|
||
// #docregion cpp-method-flutter | ||
class PigeonFlutterApi { | ||
public: | ||
PigeonFlutterApi(flutter::BinaryMessenger* messenger) | ||
: flutterApi_(std::make_unique<MessageFlutterApi>(messenger)) {} | ||
|
||
void CallFlutterMethod( | ||
const std::string& a_string, | ||
std::function<void(ErrorOr<std::string> reply)> result) { | ||
flutterApi_->FlutterMethod( | ||
&a_string, [result](const std::string& echo) { result(echo); }, | ||
[result](const FlutterError& error) { result(error); }); | ||
} | ||
|
||
private: | ||
std::unique_ptr<MessageFlutterApi> flutterApi_; | ||
}; | ||
// #enddocregion cpp-method-flutter | ||
|
||
} // namespace | ||
|
||
FlutterWindow::FlutterWindow(const flutter::DartProject& project) | ||
|
@@ -49,15 +75,6 @@ bool FlutterWindow::OnCreate() { | |
return false; | ||
} | ||
|
||
// #docregion cpp-method-flutter | ||
void TestPlugin::CallFlutterMethod( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code was not fully C++, and was in the wrong place (as in, this isn't a valid place for this definition to exist in C++). I pulled it out into a class to match Swift and Kotlin, and updated it to compile. |
||
String aString, std::function<void(ErrorOr<int64_t> reply)> result) { | ||
MessageFlutterApi->FlutterMethod( | ||
aString, [result](String echo) { result(echo); }, | ||
[result](const FlutterError& error) { result(error); }); | ||
} | ||
// #enddocregion cpp-method-flutter | ||
|
||
RECT frame = GetClientArea(); | ||
|
||
// The size here must match the window dimensions to avoid unnecessary surface | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the constructor->init change were an Android Studio-suggested refactor; I figured I might as well update it to follow recommendations while I was there, but I can back this part out if we don't want it.