1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 22:38:42 +00:00

Add a pigeon sample that demonstrates a "realistic" integration scenario with middleware and business logic (#465)

This commit is contained in:
xster
2020-06-12 23:18:05 -07:00
committed by GitHub
parent 87c9cfa995
commit 70976eeb28
47 changed files with 1966 additions and 3 deletions

View File

@@ -0,0 +1,100 @@
// Autogenerated from Pigeon (v0.1.0), 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
import 'dart:async';
import 'package:flutter/services.dart';
class Book {
String title;
String subtitle;
String author;
String description;
String publishDate;
int pageCount;
// ignore: unused_element
Map<dynamic, dynamic> _toMap() {
final Map<dynamic, dynamic> pigeonMap = <dynamic, dynamic>{};
pigeonMap['title'] = title;
pigeonMap['subtitle'] = subtitle;
pigeonMap['author'] = author;
pigeonMap['description'] = description;
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;
}
}
abstract class FlutterBookApi {
void displayBookDetails(Book arg);
static void setup(FlutterBookApi api) {
{
const BasicMessageChannel<dynamic> channel = BasicMessageChannel<dynamic>(
'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);
});
}
}
}
class HostBookApi {
Future<void> cancel() async {
const BasicMessageChannel<dynamic> channel = BasicMessageChannel<dynamic>(
'dev.flutter.pigeon.HostBookApi.cancel', StandardMessageCodec());
final Map<dynamic, dynamic> replyMap = await channel.send(null);
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
details: null);
} else if (replyMap['error'] != null) {
final Map<dynamic, dynamic> error = replyMap['error'];
throw PlatformException(
code: error['code'],
message: error['message'],
details: error['details']);
} else {
// noop
}
}
Future<void> finishEditingBook(Book arg) async {
final Map<dynamic, dynamic> requestMap = arg._toMap();
const BasicMessageChannel<dynamic> channel = BasicMessageChannel<dynamic>(
'dev.flutter.pigeon.HostBookApi.finishEditingBook',
StandardMessageCodec());
final Map<dynamic, dynamic> replyMap = await channel.send(requestMap);
if (replyMap == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
details: null);
} else if (replyMap['error'] != null) {
final Map<dynamic, dynamic> error = replyMap['error'];
throw PlatformException(
code: error['code'],
message: error['message'],
details: error['details']);
} else {
// noop
}
}
}