mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
Added iOS example for add-to-app Pigeon (#722)
This commit is contained in:
@@ -1,38 +1,42 @@
|
||||
// Autogenerated from Pigeon (v0.1.0), do not edit directly.
|
||||
// Autogenerated from Pigeon (v0.1.17), 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
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List;
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class Book {
|
||||
String title;
|
||||
String subtitle;
|
||||
String author;
|
||||
String description;
|
||||
String summary;
|
||||
String publishDate;
|
||||
int pageCount;
|
||||
|
||||
// ignore: unused_element
|
||||
Map<dynamic, dynamic> _toMap() {
|
||||
final Map<dynamic, dynamic> pigeonMap = <dynamic, dynamic>{};
|
||||
Object encode() {
|
||||
final Map<Object, Object> pigeonMap = <Object, Object>{};
|
||||
pigeonMap['title'] = title;
|
||||
pigeonMap['subtitle'] = subtitle;
|
||||
pigeonMap['author'] = author;
|
||||
pigeonMap['description'] = description;
|
||||
pigeonMap['summary'] = summary;
|
||||
pigeonMap['publishDate'] = publishDate;
|
||||
pigeonMap['pageCount'] = pageCount;
|
||||
return pigeonMap;
|
||||
}
|
||||
|
||||
// ignore: unused_element
|
||||
static Book _fromMap(Map<dynamic, dynamic> pigeonMap) {
|
||||
final Book result = Book();
|
||||
result.title = pigeonMap['title'];
|
||||
result.subtitle = pigeonMap['subtitle'];
|
||||
result.author = pigeonMap['author'];
|
||||
result.description = pigeonMap['description'];
|
||||
result.publishDate = pigeonMap['publishDate'];
|
||||
result.pageCount = pigeonMap['pageCount'];
|
||||
return result;
|
||||
static Book decode(Object message) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,59 +44,71 @@ abstract class FlutterBookApi {
|
||||
void displayBookDetails(Book arg);
|
||||
static void setup(FlutterBookApi api) {
|
||||
{
|
||||
const BasicMessageChannel<dynamic> channel = BasicMessageChannel<dynamic>(
|
||||
const BasicMessageChannel<Object> channel = BasicMessageChannel<Object>(
|
||||
'dev.flutter.pigeon.FlutterBookApi.displayBookDetails',
|
||||
StandardMessageCodec());
|
||||
channel.setMessageHandler((dynamic message) async {
|
||||
final Map<dynamic, dynamic> mapMessage =
|
||||
message as Map<dynamic, dynamic>;
|
||||
final Book input = Book._fromMap(mapMessage);
|
||||
api.displayBookDetails(input);
|
||||
});
|
||||
if (api == null) {
|
||||
channel.setMessageHandler(null);
|
||||
} else {
|
||||
channel.setMessageHandler((Object message) async {
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
final Book input = Book.decode(message);
|
||||
api.displayBookDetails(input);
|
||||
return;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class HostBookApi {
|
||||
Future<void> cancel() async {
|
||||
const BasicMessageChannel<dynamic> channel = BasicMessageChannel<dynamic>(
|
||||
const BasicMessageChannel<Object> channel = BasicMessageChannel<Object>(
|
||||
'dev.flutter.pigeon.HostBookApi.cancel', StandardMessageCodec());
|
||||
|
||||
final Map<dynamic, dynamic> replyMap = await channel.send(null);
|
||||
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);
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
details: null,
|
||||
);
|
||||
} else if (replyMap['error'] != null) {
|
||||
final Map<dynamic, dynamic> error = replyMap['error'];
|
||||
final Map<Object, Object> error =
|
||||
replyMap['error'] as Map<Object, Object>;
|
||||
throw PlatformException(
|
||||
code: error['code'],
|
||||
message: error['message'],
|
||||
details: error['details']);
|
||||
code: error['code'] as String,
|
||||
message: error['message'] as String,
|
||||
details: error['details'],
|
||||
);
|
||||
} else {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> finishEditingBook(Book arg) async {
|
||||
final Map<dynamic, dynamic> requestMap = arg._toMap();
|
||||
const BasicMessageChannel<dynamic> channel = BasicMessageChannel<dynamic>(
|
||||
final Object encoded = arg.encode();
|
||||
const BasicMessageChannel<Object> channel = BasicMessageChannel<Object>(
|
||||
'dev.flutter.pigeon.HostBookApi.finishEditingBook',
|
||||
StandardMessageCodec());
|
||||
|
||||
final Map<dynamic, dynamic> replyMap = await channel.send(requestMap);
|
||||
final Map<Object, Object> replyMap =
|
||||
await channel.send(encoded) as Map<Object, Object>;
|
||||
if (replyMap == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
details: null);
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
details: null,
|
||||
);
|
||||
} else if (replyMap['error'] != null) {
|
||||
final Map<dynamic, dynamic> error = replyMap['error'];
|
||||
final Map<Object, Object> error =
|
||||
replyMap['error'] as Map<Object, Object>;
|
||||
throw PlatformException(
|
||||
code: error['code'],
|
||||
message: error['message'],
|
||||
details: error['details']);
|
||||
code: error['code'] as String,
|
||||
message: error['message'] as String,
|
||||
details: error['details'],
|
||||
);
|
||||
} else {
|
||||
// noop
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ class _BookDetailState extends State<BookDetail> {
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
Text(
|
||||
book.description,
|
||||
book.summary,
|
||||
style: TextStyle(color: Colors.grey.shade600, height: 1.24),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user