mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
updated add_to_app sample to pigeon 1.0 (#894)
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
// Autogenerated from Pigeon (v0.1.17), do not edit directly.
|
||||
// Autogenerated from Pigeon (v1.0.1), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
|
||||
package dev.flutter.example.books;
|
||||
|
||||
import io.flutter.plugin.common.BasicMessageChannel;
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.MessageCodec;
|
||||
import io.flutter.plugin.common.StandardMessageCodec;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** Generated class from Pigeon. */
|
||||
@SuppressWarnings("unused")
|
||||
@SuppressWarnings(
|
||||
{"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"})
|
||||
public class Api {
|
||||
|
||||
/** Generated class from Pigeon that represents data sent in messages. */
|
||||
@@ -33,23 +40,33 @@ public class Api {
|
||||
|
||||
private String publishDate;
|
||||
public String getPublishDate() { return publishDate; }
|
||||
public void setPublishDate(String setterArg) { this.publishDate = setterArg; }
|
||||
public void setPublishDate(String setterArg) {
|
||||
this.publishDate = setterArg;
|
||||
}
|
||||
|
||||
private Long pageCount;
|
||||
public Long getPageCount() { return pageCount; }
|
||||
public void setPageCount(Long setterArg) { this.pageCount = setterArg; }
|
||||
|
||||
HashMap toMap() {
|
||||
HashMap<String, Object> toMapResult = new HashMap<>();
|
||||
private Thumbnail thumbnail;
|
||||
public Thumbnail getThumbnail() { return thumbnail; }
|
||||
public void setThumbnail(Thumbnail setterArg) {
|
||||
this.thumbnail = setterArg;
|
||||
}
|
||||
|
||||
Map<String, Object> toMap() {
|
||||
Map<String, Object> toMapResult = new HashMap<>();
|
||||
toMapResult.put("title", title);
|
||||
toMapResult.put("subtitle", subtitle);
|
||||
toMapResult.put("author", author);
|
||||
toMapResult.put("summary", summary);
|
||||
toMapResult.put("publishDate", publishDate);
|
||||
toMapResult.put("pageCount", pageCount);
|
||||
toMapResult.put("thumbnail",
|
||||
(thumbnail == null) ? null : thumbnail.toMap());
|
||||
return toMapResult;
|
||||
}
|
||||
static Book fromMap(HashMap map) {
|
||||
static Book fromMap(Map<String, Object> map) {
|
||||
Book fromMapResult = new Book();
|
||||
Object title = map.get("title");
|
||||
fromMapResult.title = (String)title;
|
||||
@@ -62,48 +79,135 @@ public class Api {
|
||||
Object publishDate = map.get("publishDate");
|
||||
fromMapResult.publishDate = (String)publishDate;
|
||||
Object pageCount = map.get("pageCount");
|
||||
fromMapResult.pageCount = (pageCount == null) ? null : ((pageCount instanceof Integer) ? (Integer)pageCount : (Long)pageCount);
|
||||
fromMapResult.pageCount =
|
||||
(pageCount == null)
|
||||
? null
|
||||
: ((pageCount instanceof Integer) ? (Integer)pageCount
|
||||
: (Long)pageCount);
|
||||
Object thumbnail = map.get("thumbnail");
|
||||
fromMapResult.thumbnail = Thumbnail.fromMap((Map)thumbnail);
|
||||
return fromMapResult;
|
||||
}
|
||||
}
|
||||
|
||||
/** Generated class from Pigeon that represents Flutter messages that can be called from Java.*/
|
||||
/** Generated class from Pigeon that represents data sent in messages. */
|
||||
public static class Thumbnail {
|
||||
private String url;
|
||||
public String getUrl() { return url; }
|
||||
public void setUrl(String setterArg) { this.url = setterArg; }
|
||||
|
||||
Map<String, Object> toMap() {
|
||||
Map<String, Object> toMapResult = new HashMap<>();
|
||||
toMapResult.put("url", url);
|
||||
return toMapResult;
|
||||
}
|
||||
static Thumbnail fromMap(Map<String, Object> map) {
|
||||
Thumbnail fromMapResult = new Thumbnail();
|
||||
Object url = map.get("url");
|
||||
fromMapResult.url = (String)url;
|
||||
return fromMapResult;
|
||||
}
|
||||
}
|
||||
private static class FlutterBookApiCodec extends StandardMessageCodec {
|
||||
public static final FlutterBookApiCodec INSTANCE =
|
||||
new FlutterBookApiCodec();
|
||||
private FlutterBookApiCodec() {}
|
||||
@Override
|
||||
protected Object readValueOfType(byte type, ByteBuffer buffer) {
|
||||
switch (type) {
|
||||
case (byte)128:
|
||||
return Book.fromMap((Map<String, Object>)readValue(buffer));
|
||||
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void writeValue(ByteArrayOutputStream stream, Object value) {
|
||||
if (value instanceof Book) {
|
||||
stream.write(128);
|
||||
writeValue(stream, ((Book)value).toMap());
|
||||
} else {
|
||||
super.writeValue(stream, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated class from Pigeon that represents Flutter messages that can be
|
||||
* called from Java.
|
||||
*/
|
||||
public static class FlutterBookApi {
|
||||
private final BinaryMessenger binaryMessenger;
|
||||
public FlutterBookApi(BinaryMessenger argBinaryMessenger){
|
||||
public FlutterBookApi(BinaryMessenger argBinaryMessenger) {
|
||||
this.binaryMessenger = argBinaryMessenger;
|
||||
}
|
||||
public interface Reply<T> {
|
||||
void reply(T reply);
|
||||
}
|
||||
public void displayBookDetails(Book argInput, Reply<Void> callback) {
|
||||
BasicMessageChannel<Object> channel =
|
||||
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FlutterBookApi.displayBookDetails", new StandardMessageCodec());
|
||||
HashMap inputMap = argInput.toMap();
|
||||
channel.send(inputMap, channelReply -> {
|
||||
callback.reply(null);
|
||||
});
|
||||
static MessageCodec<Object> getCodec() {
|
||||
return FlutterBookApiCodec.INSTANCE;
|
||||
}
|
||||
|
||||
public void displayBookDetails(Book bookArg, Reply<Void> callback) {
|
||||
BasicMessageChannel<Object> channel = new BasicMessageChannel<>(
|
||||
binaryMessenger,
|
||||
"dev.flutter.pigeon.FlutterBookApi.displayBookDetails", getCodec());
|
||||
channel.send(new ArrayList<Object>(Arrays.asList(bookArg)),
|
||||
channelReply -> { callback.reply(null); });
|
||||
}
|
||||
}
|
||||
private static class HostBookApiCodec extends StandardMessageCodec {
|
||||
public static final HostBookApiCodec INSTANCE = new HostBookApiCodec();
|
||||
private HostBookApiCodec() {}
|
||||
@Override
|
||||
protected Object readValueOfType(byte type, ByteBuffer buffer) {
|
||||
switch (type) {
|
||||
case (byte)128:
|
||||
return Book.fromMap((Map<String, Object>)readValue(buffer));
|
||||
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void writeValue(ByteArrayOutputStream stream, Object value) {
|
||||
if (value instanceof Book) {
|
||||
stream.write(128);
|
||||
writeValue(stream, ((Book)value).toMap());
|
||||
} else {
|
||||
super.writeValue(stream, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
|
||||
/**
|
||||
* Generated interface from Pigeon that represents a handler of messages from
|
||||
* Flutter.
|
||||
*/
|
||||
public interface HostBookApi {
|
||||
void cancel();
|
||||
void finishEditingBook(Book arg);
|
||||
void finishEditingBook(Book book);
|
||||
|
||||
/** Sets up an instance of `HostBookApi` to handle messages through the `binaryMessenger` */
|
||||
/** The codec used by HostBookApi. */
|
||||
static MessageCodec<Object> getCodec() { return HostBookApiCodec.INSTANCE; }
|
||||
|
||||
/**
|
||||
* Sets up an instance of `HostBookApi` to handle messages through the
|
||||
* `binaryMessenger`.
|
||||
*/
|
||||
static void setup(BinaryMessenger binaryMessenger, HostBookApi api) {
|
||||
{
|
||||
BasicMessageChannel<Object> channel =
|
||||
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.HostBookApi.cancel", new StandardMessageCodec());
|
||||
BasicMessageChannel<Object> channel = new BasicMessageChannel<>(
|
||||
binaryMessenger, "dev.flutter.pigeon.HostBookApi.cancel",
|
||||
getCodec());
|
||||
if (api != null) {
|
||||
channel.setMessageHandler((message, reply) -> {
|
||||
HashMap<String, HashMap> wrapped = new HashMap<>();
|
||||
Map<String, Object> wrapped = new HashMap<>();
|
||||
try {
|
||||
api.cancel();
|
||||
wrapped.put("result", null);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
} catch (Error | RuntimeException exception) {
|
||||
wrapped.put("error", wrapError(exception));
|
||||
}
|
||||
reply.reply(wrapped);
|
||||
@@ -113,18 +217,21 @@ public class Api {
|
||||
}
|
||||
}
|
||||
{
|
||||
BasicMessageChannel<Object> channel =
|
||||
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.HostBookApi.finishEditingBook", new StandardMessageCodec());
|
||||
BasicMessageChannel<Object> channel = new BasicMessageChannel<>(
|
||||
binaryMessenger, "dev.flutter.pigeon.HostBookApi.finishEditingBook",
|
||||
getCodec());
|
||||
if (api != null) {
|
||||
channel.setMessageHandler((message, reply) -> {
|
||||
HashMap<String, HashMap> wrapped = new HashMap<>();
|
||||
Map<String, Object> wrapped = new HashMap<>();
|
||||
try {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
Book input = Book.fromMap((HashMap)message);
|
||||
api.finishEditingBook(input);
|
||||
wrapped.put("result", null);
|
||||
ArrayList<Object> args = (ArrayList<Object>)message;
|
||||
Book bookArg = (Book)args.get(0);
|
||||
if (bookArg == null) {
|
||||
throw new NullPointerException("bookArg unexpectedly null.");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
api.finishEditingBook(bookArg);
|
||||
wrapped.put("result", null);
|
||||
} catch (Error | RuntimeException exception) {
|
||||
wrapped.put("error", wrapError(exception));
|
||||
}
|
||||
reply.reply(wrapped);
|
||||
@@ -135,8 +242,8 @@ public class Api {
|
||||
}
|
||||
}
|
||||
}
|
||||
private static HashMap wrapError(Exception exception) {
|
||||
HashMap<String, Object> errorMap = new HashMap<>();
|
||||
private static Map<String, Object> wrapError(Throwable exception) {
|
||||
Map<String, Object> errorMap = new HashMap<>();
|
||||
errorMap.put("message", exception.toString());
|
||||
errorMap.put("code", exception.getClass().getSimpleName());
|
||||
errorMap.put("details", null);
|
||||
|
||||
@@ -43,7 +43,7 @@ class FlutterBookActivity: FlutterActivity() {
|
||||
// TODO(gaaclarke): the Pigeon generated data class should just implement
|
||||
// Serializable so we won't need 'toMap()' here
|
||||
// https://github.com/flutter/flutter/issues/58909
|
||||
book.toMap()
|
||||
HashMap(book.toMap())
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class FlutterBookActivity: FlutterActivity() {
|
||||
* activity's {@code onActivityResult}.
|
||||
*/
|
||||
fun getBookFromResultIntent(resultIntent: Intent): Api.Book {
|
||||
return Api.Book.fromMap(resultIntent.getSerializableExtra(FlutterBookActivity.EXTRA_BOOK) as HashMap<*, *>);
|
||||
return Api.Book.fromMap((resultIntent.getSerializableExtra(FlutterBookActivity.EXTRA_BOOK) as HashMap<String, Any>));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class FlutterBookActivity: FlutterActivity() {
|
||||
|
||||
// The book to give to Flutter is passed in from the MainActivity via this activity's
|
||||
// source intent getter. The intent contains the book serialized as on extra.
|
||||
val bookToShow = Api.Book.fromMap(intent.getSerializableExtra(EXTRA_BOOK) as HashMap<*, *>)
|
||||
val bookToShow = Api.Book.fromMap(intent.getSerializableExtra(EXTRA_BOOK) as HashMap<String, Any>)
|
||||
|
||||
// Register the HostBookApiHandler callback class to get results from Flutter.
|
||||
Api.HostBookApi.setup(flutterEngine.dartExecutor, HostBookApiHandler())
|
||||
@@ -94,7 +94,7 @@ class FlutterBookActivity: FlutterActivity() {
|
||||
}
|
||||
// Flutter returned an edited book instance. Return it to the MainActivity via the
|
||||
// standard Android Activity set result mechanism.
|
||||
setResult(Activity.RESULT_OK, Intent().putExtra(EXTRA_BOOK, book.toMap()))
|
||||
setResult(Activity.RESULT_OK, Intent().putExtra(EXTRA_BOOK, HashMap(book.toMap())))
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,107 @@
|
||||
// Autogenerated from Pigeon (v0.1.17), do not edit directly.
|
||||
// Autogenerated from Pigeon (v1.0.1), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import
|
||||
// @dart = 2.8
|
||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name
|
||||
// @dart = 2.12
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List;
|
||||
|
||||
import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer;
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class Book {
|
||||
String title;
|
||||
String subtitle;
|
||||
String author;
|
||||
String summary;
|
||||
String publishDate;
|
||||
int pageCount;
|
||||
String? title;
|
||||
String? subtitle;
|
||||
String? author;
|
||||
String? summary;
|
||||
String? publishDate;
|
||||
int? pageCount;
|
||||
Thumbnail? thumbnail;
|
||||
|
||||
// ignore: unused_element
|
||||
Object encode() {
|
||||
final Map<Object, Object> pigeonMap = <Object, Object>{};
|
||||
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
|
||||
pigeonMap['title'] = title;
|
||||
pigeonMap['subtitle'] = subtitle;
|
||||
pigeonMap['author'] = author;
|
||||
pigeonMap['summary'] = summary;
|
||||
pigeonMap['publishDate'] = publishDate;
|
||||
pigeonMap['pageCount'] = pageCount;
|
||||
pigeonMap['thumbnail'] = thumbnail == null ? null : thumbnail!.encode();
|
||||
return pigeonMap;
|
||||
}
|
||||
|
||||
// ignore: unused_element
|
||||
static Book decode(Object message) {
|
||||
final Map<Object, Object> pigeonMap = message as Map<Object, Object>;
|
||||
final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>;
|
||||
return Book()
|
||||
..title = pigeonMap['title'] as String
|
||||
..subtitle = pigeonMap['subtitle'] as String
|
||||
..author = pigeonMap['author'] as String
|
||||
..summary = pigeonMap['summary'] as String
|
||||
..publishDate = pigeonMap['publishDate'] as String
|
||||
..pageCount = pigeonMap['pageCount'] as int;
|
||||
..title = pigeonMap['title'] as String?
|
||||
..subtitle = pigeonMap['subtitle'] as String?
|
||||
..author = pigeonMap['author'] as String?
|
||||
..summary = pigeonMap['summary'] as String?
|
||||
..publishDate = pigeonMap['publishDate'] as String?
|
||||
..pageCount = pigeonMap['pageCount'] as int?
|
||||
..thumbnail = pigeonMap['thumbnail'] != null
|
||||
? Thumbnail.decode(pigeonMap['thumbnail']!)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
class Thumbnail {
|
||||
String? url;
|
||||
|
||||
Object encode() {
|
||||
final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
|
||||
pigeonMap['url'] = url;
|
||||
return pigeonMap;
|
||||
}
|
||||
|
||||
static Thumbnail decode(Object message) {
|
||||
final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>;
|
||||
return Thumbnail()..url = pigeonMap['url'] as String?;
|
||||
}
|
||||
}
|
||||
|
||||
class _FlutterBookApiCodec extends StandardMessageCodec {
|
||||
const _FlutterBookApiCodec();
|
||||
@override
|
||||
void writeValue(WriteBuffer buffer, Object? value) {
|
||||
if (value is Book) {
|
||||
buffer.putUint8(128);
|
||||
writeValue(buffer, value.encode());
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
case 128:
|
||||
return Book.decode(readValue(buffer)!);
|
||||
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class FlutterBookApi {
|
||||
static const MessageCodec<Object?> codec = _FlutterBookApiCodec();
|
||||
|
||||
void displayBookDetails(Book book);
|
||||
static void setup(FlutterBookApi api) {
|
||||
static void setup(FlutterBookApi? api) {
|
||||
{
|
||||
const BasicMessageChannel<Object> channel = BasicMessageChannel<Object>(
|
||||
'dev.flutter.pigeon.FlutterBookApi.displayBookDetails',
|
||||
StandardMessageCodec());
|
||||
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.FlutterBookApi.displayBookDetails', codec);
|
||||
if (api == null) {
|
||||
channel.setMessageHandler(null);
|
||||
} else {
|
||||
channel.setMessageHandler((message) async {
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
final Book input = Book.decode(message);
|
||||
api.displayBookDetails(input);
|
||||
channel.setMessageHandler((Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.FlutterBookApi.displayBookDetails was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final Book? arg_book = args[0] as Book?;
|
||||
assert(arg_book != null,
|
||||
'Argument for dev.flutter.pigeon.FlutterBookApi.displayBookDetails was null, expected non-null Book.');
|
||||
api.displayBookDetails(arg_book!);
|
||||
return;
|
||||
});
|
||||
}
|
||||
@@ -63,38 +109,47 @@ abstract class FlutterBookApi {
|
||||
}
|
||||
}
|
||||
|
||||
class HostBookApi {
|
||||
Future<void> cancel() async {
|
||||
const BasicMessageChannel<Object> channel = BasicMessageChannel<Object>(
|
||||
'dev.flutter.pigeon.HostBookApi.cancel', StandardMessageCodec());
|
||||
final Map<Object, Object> replyMap =
|
||||
await channel.send(null) as Map<Object, Object>;
|
||||
if (replyMap == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
details: null,
|
||||
);
|
||||
} else if (replyMap['error'] != null) {
|
||||
final Map<Object, Object> error =
|
||||
replyMap['error'] as Map<Object, Object>;
|
||||
throw PlatformException(
|
||||
code: error['code'] as String,
|
||||
message: error['message'] as String,
|
||||
details: error['details'],
|
||||
);
|
||||
class _HostBookApiCodec extends StandardMessageCodec {
|
||||
const _HostBookApiCodec();
|
||||
@override
|
||||
void writeValue(WriteBuffer buffer, Object? value) {
|
||||
if (value is Book) {
|
||||
buffer.putUint8(128);
|
||||
writeValue(buffer, value.encode());
|
||||
} else {
|
||||
// noop
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> finishEditingBook(Book arg) async {
|
||||
final Object encoded = arg.encode();
|
||||
const BasicMessageChannel<Object> channel = BasicMessageChannel<Object>(
|
||||
'dev.flutter.pigeon.HostBookApi.finishEditingBook',
|
||||
StandardMessageCodec());
|
||||
final Map<Object, Object> replyMap =
|
||||
await channel.send(encoded) as Map<Object, Object>;
|
||||
@override
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
case 128:
|
||||
return Book.decode(readValue(buffer)!);
|
||||
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class HostBookApi {
|
||||
/// Constructor for [HostBookApi]. The [binaryMessenger] named argument is
|
||||
/// available for dependency injection. If it is left null, the default
|
||||
/// BinaryMessenger will be used which routes to the host platform.
|
||||
HostBookApi({BinaryMessenger? binaryMessenger})
|
||||
: _binaryMessenger = binaryMessenger;
|
||||
|
||||
final BinaryMessenger? _binaryMessenger;
|
||||
|
||||
static const MessageCodec<Object?> codec = _HostBookApiCodec();
|
||||
|
||||
Future<void> cancel() async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.HostBookApi.cancel', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final Map<Object?, Object?>? replyMap =
|
||||
await channel.send(null) as Map<Object?, Object?>?;
|
||||
if (replyMap == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
@@ -102,15 +157,40 @@ class HostBookApi {
|
||||
details: null,
|
||||
);
|
||||
} else if (replyMap['error'] != null) {
|
||||
final Map<Object, Object> error =
|
||||
replyMap['error'] as Map<Object, Object>;
|
||||
final Map<Object?, Object?> error =
|
||||
(replyMap['error'] as Map<Object?, Object?>?)!;
|
||||
throw PlatformException(
|
||||
code: error['code'] as String,
|
||||
message: error['message'] as String,
|
||||
code: (error['code'] as String?)!,
|
||||
message: error['message'] as String?,
|
||||
details: error['details'],
|
||||
);
|
||||
} else {
|
||||
// noop
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> finishEditingBook(Book arg_book) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.HostBookApi.finishEditingBook', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final Map<Object?, Object?>? replyMap =
|
||||
await channel.send(<Object>[arg_book]) as Map<Object?, Object?>?;
|
||||
if (replyMap == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
details: null,
|
||||
);
|
||||
} else if (replyMap['error'] != null) {
|
||||
final Map<Object?, Object?> error =
|
||||
(replyMap['error'] as Map<Object?, Object?>?)!;
|
||||
throw PlatformException(
|
||||
code: (error['code'] as String?)!,
|
||||
message: error['message'] as String?,
|
||||
details: error['details'],
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,12 @@ class Book {
|
||||
String summary;
|
||||
String publishDate;
|
||||
int pageCount;
|
||||
// Thumbnail thumbnail;
|
||||
Thumbnail thumbnail;
|
||||
}
|
||||
|
||||
// TODO(gaaclarke): add this back when the https://github.com/flutter/flutter/issues/58896
|
||||
// crash is resolved.
|
||||
// class Thumbnail {
|
||||
// String url;
|
||||
// }
|
||||
class Thumbnail {
|
||||
String url;
|
||||
}
|
||||
|
||||
@FlutterApi()
|
||||
abstract class FlutterBookApi {
|
||||
|
||||
@@ -1,20 +1,34 @@
|
||||
# Generated by pub
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
_fe_analyzer_shared:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: _fe_analyzer_shared
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "22.0.0"
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.7.2"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: args
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.6.0"
|
||||
version: "2.2.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.6.1"
|
||||
version: "2.8.2"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -22,6 +36,27 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
build:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: build
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
built_collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: built_collection
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.1.1"
|
||||
built_value:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: built_value
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.1.2"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -35,7 +70,14 @@ packages:
|
||||
name: charcode
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
version: "1.3.1"
|
||||
cli_util:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: cli_util
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.3"
|
||||
clock:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -43,6 +85,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
code_builder:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: code_builder
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.1.0"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -50,6 +99,27 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.15.0"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: convert
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: crypto
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
dart_style:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: dart_style
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -57,6 +127,20 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: file
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.1.2"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: fixnum
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
@@ -74,6 +158,13 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: glob
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -81,27 +172,41 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: logging
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: matcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.10"
|
||||
version: "0.12.11"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
version: "1.7.0"
|
||||
mockito:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: mockito
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.1.1+1"
|
||||
version: "5.0.15"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: package_config
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -109,18 +214,39 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0"
|
||||
pedantic:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.11.1"
|
||||
pigeon:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: pigeon
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.23"
|
||||
version: "1.0.1"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pub_semver
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.99"
|
||||
source_gen:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_gen
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -162,7 +288,7 @@ packages:
|
||||
name: test_api
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
version: "0.4.3"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -177,5 +303,19 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
watcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: watcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: yaml
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
sdks:
|
||||
dart: ">=2.12.0 <3.0.0"
|
||||
|
||||
@@ -13,8 +13,8 @@ dependencies:
|
||||
sdk: flutter
|
||||
|
||||
dev_dependencies:
|
||||
pigeon: ^0.1.0
|
||||
mockito: ^4.1.1
|
||||
pigeon: ^1.0.0
|
||||
mockito: ^5.0.0
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^1.0.0
|
||||
|
||||
@@ -103,7 +103,7 @@ class ViewController: UITableViewController, BKHostBookApi {
|
||||
let flutterViewController = FlutterViewController.init(
|
||||
engine: appDelegate.engine, nibName: nil, bundle: nil)
|
||||
self.editingIndex = index
|
||||
api.displayBookDetails(self.books[index]) { (error) in
|
||||
api.displayBookDetailsBook(self.books[index]) { (error) in
|
||||
if let error = error {
|
||||
print(error)
|
||||
}
|
||||
@@ -114,7 +114,7 @@ class ViewController: UITableViewController, BKHostBookApi {
|
||||
/**
|
||||
Called by Pigeon when the FlutterViewController is dismissed without accepting any edits.
|
||||
*/
|
||||
func cancel(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
|
||||
func cancelWithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
|
||||
self.editingIndex = -1
|
||||
self.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
@@ -122,7 +122,7 @@ class ViewController: UITableViewController, BKHostBookApi {
|
||||
/**
|
||||
Called by Pigeon when edits to the book are accepted in the FlutterViewController.
|
||||
*/
|
||||
func finishEditing(_ input: BKBook, error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
|
||||
func finishEditingBook(_ input: BKBook, error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
|
||||
self.books[editingIndex] = input
|
||||
self.tableView.reloadData()
|
||||
self.editingIndex = -1
|
||||
|
||||
@@ -1,32 +1,49 @@
|
||||
// Autogenerated from Pigeon (v0.1.17), do not edit directly.
|
||||
// Autogenerated from Pigeon (v1.0.1), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
#import <Foundation/Foundation.h>
|
||||
@protocol FlutterBinaryMessenger;
|
||||
@protocol FlutterMessageCodec;
|
||||
@class FlutterError;
|
||||
@class FlutterStandardTypedData;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class BKBook;
|
||||
@class BKThumbnail;
|
||||
|
||||
@interface BKBook : NSObject
|
||||
@property(nonatomic, copy, nullable) NSString * title;
|
||||
@property(nonatomic, copy, nullable) NSString * subtitle;
|
||||
@property(nonatomic, copy, nullable) NSString * author;
|
||||
@property(nonatomic, copy, nullable) NSString * summary;
|
||||
@property(nonatomic, copy, nullable) NSString * publishDate;
|
||||
@property(nonatomic, strong, nullable) NSNumber * pageCount;
|
||||
@property(nonatomic, copy, nullable) NSString *title;
|
||||
@property(nonatomic, copy, nullable) NSString *subtitle;
|
||||
@property(nonatomic, copy, nullable) NSString *author;
|
||||
@property(nonatomic, copy, nullable) NSString *summary;
|
||||
@property(nonatomic, copy, nullable) NSString *publishDate;
|
||||
@property(nonatomic, strong, nullable) NSNumber *pageCount;
|
||||
@property(nonatomic, strong, nullable) BKThumbnail *thumbnail;
|
||||
@end
|
||||
|
||||
@interface BKThumbnail : NSObject
|
||||
@property(nonatomic, copy, nullable) NSString *url;
|
||||
@end
|
||||
|
||||
/// The codec used by BKFlutterBookApi.
|
||||
NSObject<FlutterMessageCodec> *BKFlutterBookApiGetCodec(void);
|
||||
|
||||
@interface BKFlutterBookApi : NSObject
|
||||
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;
|
||||
- (void)displayBookDetails:(BKBook*)input completion:(void(^)(NSError* _Nullable))completion;
|
||||
- (instancetype)initWithBinaryMessenger:
|
||||
(id<FlutterBinaryMessenger>)binaryMessenger;
|
||||
- (void)displayBookDetailsBook:(BKBook *)book
|
||||
completion:(void (^)(NSError *_Nullable))completion;
|
||||
@end
|
||||
/// The codec used by BKHostBookApi.
|
||||
NSObject<FlutterMessageCodec> *BKHostBookApiGetCodec(void);
|
||||
|
||||
@protocol BKHostBookApi
|
||||
-(void)cancel:(FlutterError *_Nullable *_Nonnull)error;
|
||||
-(void)finishEditingBook:(BKBook*)input error:(FlutterError *_Nullable *_Nonnull)error;
|
||||
- (void)cancelWithError:(FlutterError *_Nullable *_Nonnull)error;
|
||||
- (void)finishEditingBookBook:(BKBook *)book
|
||||
error:(FlutterError *_Nullable *_Nonnull)error;
|
||||
@end
|
||||
|
||||
extern void BKHostBookApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<BKHostBookApi> _Nullable api);
|
||||
extern void BKHostBookApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
|
||||
NSObject<BKHostBookApi> *_Nullable api);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Autogenerated from Pigeon (v0.1.17), do not edit directly.
|
||||
// Autogenerated from Pigeon (v1.0.1), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
#import "api.h"
|
||||
#import <Flutter/Flutter.h>
|
||||
@@ -7,29 +7,34 @@
|
||||
#error File requires ARC to be enabled.
|
||||
#endif
|
||||
|
||||
static NSDictionary* wrapResult(NSDictionary *result, FlutterError *error) {
|
||||
static NSDictionary<NSString *, id> *wrapResult(id result,
|
||||
FlutterError *error) {
|
||||
NSDictionary *errorDict = (NSDictionary *)[NSNull null];
|
||||
if (error) {
|
||||
errorDict = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
(error.code ? error.code : [NSNull null]), @"code",
|
||||
(error.message ? error.message : [NSNull null]), @"message",
|
||||
(error.details ? error.details : [NSNull null]), @"details",
|
||||
nil];
|
||||
errorDict = @{
|
||||
@"code" : (error.code ? error.code : [NSNull null]),
|
||||
@"message" : (error.message ? error.message : [NSNull null]),
|
||||
@"details" : (error.details ? error.details : [NSNull null]),
|
||||
};
|
||||
}
|
||||
return [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
(result ? result : [NSNull null]), @"result",
|
||||
errorDict, @"error",
|
||||
nil];
|
||||
return @{
|
||||
@"result" : (result ? result : [NSNull null]),
|
||||
@"error" : errorDict,
|
||||
};
|
||||
}
|
||||
|
||||
@interface BKBook ()
|
||||
+(BKBook*)fromMap:(NSDictionary*)dict;
|
||||
-(NSDictionary*)toMap;
|
||||
+ (BKBook *)fromMap:(NSDictionary *)dict;
|
||||
- (NSDictionary *)toMap;
|
||||
@end
|
||||
@interface BKThumbnail ()
|
||||
+ (BKThumbnail *)fromMap:(NSDictionary *)dict;
|
||||
- (NSDictionary *)toMap;
|
||||
@end
|
||||
|
||||
@implementation BKBook
|
||||
+(BKBook*)fromMap:(NSDictionary*)dict {
|
||||
BKBook* result = [[BKBook alloc] init];
|
||||
+ (BKBook *)fromMap:(NSDictionary *)dict {
|
||||
BKBook *result = [[BKBook alloc] init];
|
||||
result.title = dict[@"title"];
|
||||
if ((NSNull *)result.title == [NSNull null]) {
|
||||
result.title = nil;
|
||||
@@ -54,68 +59,210 @@ static NSDictionary* wrapResult(NSDictionary *result, FlutterError *error) {
|
||||
if ((NSNull *)result.pageCount == [NSNull null]) {
|
||||
result.pageCount = nil;
|
||||
}
|
||||
result.thumbnail = [BKThumbnail fromMap:dict[@"thumbnail"]];
|
||||
if ((NSNull *)result.thumbnail == [NSNull null]) {
|
||||
result.thumbnail = nil;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
-(NSDictionary*)toMap {
|
||||
return [NSDictionary dictionaryWithObjectsAndKeys:(self.title ? self.title : [NSNull null]), @"title", (self.subtitle ? self.subtitle : [NSNull null]), @"subtitle", (self.author ? self.author : [NSNull null]), @"author", (self.summary ? self.summary : [NSNull null]), @"summary", (self.publishDate ? self.publishDate : [NSNull null]), @"publishDate", (self.pageCount ? self.pageCount : [NSNull null]), @"pageCount", nil];
|
||||
- (NSDictionary *)toMap {
|
||||
return [NSDictionary
|
||||
dictionaryWithObjectsAndKeys:
|
||||
(self.title ? self.title : [NSNull null]), @"title",
|
||||
(self.subtitle ? self.subtitle : [NSNull null]), @"subtitle",
|
||||
(self.author ? self.author : [NSNull null]), @"author",
|
||||
(self.summary ? self.summary : [NSNull null]), @"summary",
|
||||
(self.publishDate ? self.publishDate : [NSNull null]), @"publishDate",
|
||||
(self.pageCount ? self.pageCount : [NSNull null]), @"pageCount",
|
||||
(self.thumbnail ? [self.thumbnail toMap] : [NSNull null]),
|
||||
@"thumbnail", nil];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation BKThumbnail
|
||||
+ (BKThumbnail *)fromMap:(NSDictionary *)dict {
|
||||
BKThumbnail *result = [[BKThumbnail alloc] init];
|
||||
result.url = dict[@"url"];
|
||||
if ((NSNull *)result.url == [NSNull null]) {
|
||||
result.url = nil;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
- (NSDictionary *)toMap {
|
||||
return [NSDictionary
|
||||
dictionaryWithObjectsAndKeys:(self.url ? self.url : [NSNull null]),
|
||||
@"url", nil];
|
||||
}
|
||||
@end
|
||||
|
||||
@interface BKFlutterBookApiCodecReader : FlutterStandardReader
|
||||
@end
|
||||
@implementation BKFlutterBookApiCodecReader
|
||||
- (nullable id)readValueOfType:(UInt8)type {
|
||||
switch (type) {
|
||||
case 128:
|
||||
return [BKBook fromMap:[self readValue]];
|
||||
|
||||
default:
|
||||
return [super readValueOfType:type];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@interface BKFlutterBookApiCodecWriter : FlutterStandardWriter
|
||||
@end
|
||||
@implementation BKFlutterBookApiCodecWriter
|
||||
- (void)writeValue:(id)value {
|
||||
if ([value isKindOfClass:[BKBook class]]) {
|
||||
[self writeByte:128];
|
||||
[self writeValue:[value toMap]];
|
||||
} else {
|
||||
[super writeValue:value];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@interface BKFlutterBookApiCodecReaderWriter : FlutterStandardReaderWriter
|
||||
@end
|
||||
@implementation BKFlutterBookApiCodecReaderWriter
|
||||
- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data {
|
||||
return [[BKFlutterBookApiCodecWriter alloc] initWithData:data];
|
||||
}
|
||||
- (FlutterStandardReader *)readerWithData:(NSData *)data {
|
||||
return [[BKFlutterBookApiCodecReader alloc] initWithData:data];
|
||||
}
|
||||
@end
|
||||
|
||||
NSObject<FlutterMessageCodec> *BKFlutterBookApiGetCodec() {
|
||||
static dispatch_once_t s_pred = 0;
|
||||
static FlutterStandardMessageCodec *s_sharedObject = nil;
|
||||
dispatch_once(&s_pred, ^{
|
||||
BKFlutterBookApiCodecReaderWriter *readerWriter =
|
||||
[[BKFlutterBookApiCodecReaderWriter alloc] init];
|
||||
s_sharedObject =
|
||||
[FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
|
||||
});
|
||||
return s_sharedObject;
|
||||
}
|
||||
|
||||
@interface BKFlutterBookApi ()
|
||||
@property (nonatomic, strong) NSObject<FlutterBinaryMessenger>* binaryMessenger;
|
||||
@property(nonatomic, strong) NSObject<FlutterBinaryMessenger> *binaryMessenger;
|
||||
@end
|
||||
|
||||
@implementation BKFlutterBookApi
|
||||
- (instancetype)initWithBinaryMessenger:(NSObject<FlutterBinaryMessenger>*)binaryMessenger {
|
||||
- (instancetype)initWithBinaryMessenger:
|
||||
(NSObject<FlutterBinaryMessenger> *)binaryMessenger {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.binaryMessenger = binaryMessenger;
|
||||
_binaryMessenger = binaryMessenger;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)displayBookDetails:(BKBook*)input completion:(void(^)(NSError* _Nullable))completion {
|
||||
FlutterBasicMessageChannel *channel =
|
||||
[FlutterBasicMessageChannel
|
||||
messageChannelWithName:@"dev.flutter.pigeon.FlutterBookApi.displayBookDetails"
|
||||
binaryMessenger:self.binaryMessenger];
|
||||
NSDictionary* inputMap = [input toMap];
|
||||
[channel sendMessage:inputMap reply:^(id reply) {
|
||||
- (void)displayBookDetailsBook:(BKBook *)arg_book
|
||||
completion:(void (^)(NSError *_Nullable))completion {
|
||||
FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel
|
||||
messageChannelWithName:
|
||||
@"dev.flutter.pigeon.FlutterBookApi.displayBookDetails"
|
||||
binaryMessenger:self.binaryMessenger
|
||||
codec:BKFlutterBookApiGetCodec()];
|
||||
[channel sendMessage:@[ arg_book ]
|
||||
reply:^(id reply) {
|
||||
completion(nil);
|
||||
}];
|
||||
}
|
||||
@end
|
||||
void BKHostBookApiSetup(id<FlutterBinaryMessenger> binaryMessenger, id<BKHostBookApi> api) {
|
||||
@interface BKHostBookApiCodecReader : FlutterStandardReader
|
||||
@end
|
||||
@implementation BKHostBookApiCodecReader
|
||||
- (nullable id)readValueOfType:(UInt8)type {
|
||||
switch (type) {
|
||||
case 128:
|
||||
return [BKBook fromMap:[self readValue]];
|
||||
|
||||
default:
|
||||
return [super readValueOfType:type];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@interface BKHostBookApiCodecWriter : FlutterStandardWriter
|
||||
@end
|
||||
@implementation BKHostBookApiCodecWriter
|
||||
- (void)writeValue:(id)value {
|
||||
if ([value isKindOfClass:[BKBook class]]) {
|
||||
[self writeByte:128];
|
||||
[self writeValue:[value toMap]];
|
||||
} else {
|
||||
[super writeValue:value];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
@interface BKHostBookApiCodecReaderWriter : FlutterStandardReaderWriter
|
||||
@end
|
||||
@implementation BKHostBookApiCodecReaderWriter
|
||||
- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data {
|
||||
return [[BKHostBookApiCodecWriter alloc] initWithData:data];
|
||||
}
|
||||
- (FlutterStandardReader *)readerWithData:(NSData *)data {
|
||||
return [[BKHostBookApiCodecReader alloc] initWithData:data];
|
||||
}
|
||||
@end
|
||||
|
||||
NSObject<FlutterMessageCodec> *BKHostBookApiGetCodec() {
|
||||
static dispatch_once_t s_pred = 0;
|
||||
static FlutterStandardMessageCodec *s_sharedObject = nil;
|
||||
dispatch_once(&s_pred, ^{
|
||||
BKHostBookApiCodecReaderWriter *readerWriter =
|
||||
[[BKHostBookApiCodecReaderWriter alloc] init];
|
||||
s_sharedObject =
|
||||
[FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
|
||||
});
|
||||
return s_sharedObject;
|
||||
}
|
||||
|
||||
void BKHostBookApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
|
||||
NSObject<BKHostBookApi> *api) {
|
||||
{
|
||||
FlutterBasicMessageChannel *channel =
|
||||
[FlutterBasicMessageChannel
|
||||
FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel
|
||||
messageChannelWithName:@"dev.flutter.pigeon.HostBookApi.cancel"
|
||||
binaryMessenger:binaryMessenger];
|
||||
binaryMessenger:binaryMessenger
|
||||
codec:BKHostBookApiGetCodec()];
|
||||
if (api) {
|
||||
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
|
||||
NSCAssert(
|
||||
[api respondsToSelector:@selector(cancelWithError:)],
|
||||
@"BKHostBookApi api doesn't respond to @selector(cancelWithError:)");
|
||||
[channel
|
||||
setMessageHandler:^(id _Nullable message, FlutterReply callback) {
|
||||
FlutterError *error;
|
||||
[api cancel:&error];
|
||||
[api cancelWithError:&error];
|
||||
callback(wrapResult(nil, error));
|
||||
}];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
[channel setMessageHandler:nil];
|
||||
}
|
||||
}
|
||||
{
|
||||
FlutterBasicMessageChannel *channel =
|
||||
[FlutterBasicMessageChannel
|
||||
messageChannelWithName:@"dev.flutter.pigeon.HostBookApi.finishEditingBook"
|
||||
binaryMessenger:binaryMessenger];
|
||||
FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel
|
||||
messageChannelWithName:
|
||||
@"dev.flutter.pigeon.HostBookApi.finishEditingBook"
|
||||
binaryMessenger:binaryMessenger
|
||||
codec:BKHostBookApiGetCodec()];
|
||||
if (api) {
|
||||
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
|
||||
NSCAssert([api respondsToSelector:@selector(finishEditingBookBook:
|
||||
error:)],
|
||||
@"BKHostBookApi api doesn't respond to "
|
||||
@"@selector(finishEditingBookBook:error:)");
|
||||
[channel
|
||||
setMessageHandler:^(id _Nullable message, FlutterReply callback) {
|
||||
NSArray *args = message;
|
||||
BKBook *arg_book = args[0];
|
||||
FlutterError *error;
|
||||
BKBook *input = [BKBook fromMap:message];
|
||||
[api finishEditingBook:input error:&error];
|
||||
[api finishEditingBookBook:arg_book error:&error];
|
||||
callback(wrapResult(nil, error));
|
||||
}];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
[channel setMessageHandler:nil];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ EXTERNAL SOURCES:
|
||||
:path: "../flutter_module_books/.ios/Flutter/FlutterPluginRegistrant"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Flutter: ac41d61a47ae5bf8195a5598d2d63754888ec0d5
|
||||
Flutter: bdfa2e8fe0e2880a2c6a58a0b1a8675c262a07af
|
||||
flutter_module_books: 537fdde264c187fc97299f730dd35974055cac20
|
||||
FlutterPluginRegistrant: 2afd5ea46d3a949472c9b7da6462d8fbf7d8b16e
|
||||
|
||||
|
||||
Reference in New Issue
Block a user