[infra_ui] Refactor platform interface to infra_ui scope and remove keyboard interface

This commit is contained in:
Jaylen Bian 2021-07-18 13:07:32 +08:00
parent cb3ed0a308
commit 5e6c014226
31 changed files with 164 additions and 94 deletions

View File

@ -8,5 +8,5 @@ import Foundation
import flowy_infra_ui
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlowyInfraUiPlugin.register(with: registry.registrar(forPlugin: "FlowyInfraUiPlugin"))
FlowyInfraUIPlugin.register(with: registry.registrar(forPlugin: "FlowyInfraUIPlugin"))
}

View File

@ -99,6 +99,20 @@ packages:
relative: true
source: path
version: "0.0.1"
flowy_infra_ui_platform_interface:
dependency: transitive
description:
path: "../flowy_infra_ui_platform_interface"
relative: true
source: path
version: "0.0.1"
flowy_infra_ui_web:
dependency: transitive
description:
path: "../flowy_infra_ui_web"
relative: true
source: path
version: "0.0.1"
flutter:
dependency: "direct main"
description: flutter
@ -177,6 +191,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
provider:
dependency: "direct main"
description:

View File

@ -4,9 +4,9 @@
#include "generated_plugin_registrant.h"
#include <flowy_infra_ui/flowy_infra_ui_plugin.h>
#include <flowy_infra_ui/flowy_infra_u_i_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
FlowyInfraUiPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlowyInfraUiPlugin"));
FlowyInfraUIPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlowyInfraUIPlugin"));
}

View File

@ -1,4 +1,4 @@
# keyboard_platform_interface
# flowy_infra_ui_platform_interface
A new Flutter package project.

View File

@ -0,0 +1,27 @@
library flowy_infra_ui_platform_interface;
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'src/method_channel_flowy_infra_ui.dart';
abstract class FlowyInfraUIPlatform extends PlatformInterface {
FlowyInfraUIPlatform() : super(token: _token);
static final Object _token = Object();
static FlowyInfraUIPlatform _instance = MethodChannelFlowyInfraUI();
static FlowyInfraUIPlatform get instance => _instance;
static set instance(FlowyInfraUIPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
Stream<bool> get onKeyboardVisibilityChange {
throw UnimplementedError('`onKeyboardChange` should be overrided by subclass.');
}
Future<String?> getPlatformVersion() {
throw UnimplementedError('`getPlatformVersion` should be overrided by subclass.');
}
}

View File

@ -0,0 +1,26 @@
import 'package:flowy_infra_ui_platform_interface/flowy_infra_ui_platform_interface.dart';
import 'package:flutter/services.dart';
import '../flowy_infra_ui_platform_interface.dart';
// ignore: constant_identifier_names
const INFRA_UI_METHOD_CHANNEL_NAME = 'flowy_infra_ui_method';
const INFRA_UI_KEYBOARD_EVENT_CHANNEL_NAME = 'flowy_infra_ui_event/keyboard';
const INFRA_UI_METHOD_GET_PLATFORM_VERSION = 'getPlatformVersion';
class MethodChannelFlowyInfraUI extends FlowyInfraUIPlatform {
final MethodChannel _methodChannel = const MethodChannel(INFRA_UI_METHOD_CHANNEL_NAME);
final EventChannel _keyboardChannel = const EventChannel(INFRA_UI_KEYBOARD_EVENT_CHANNEL_NAME);
late final Stream<bool> _onKeyboardVisibilityChange =
_keyboardChannel.receiveBroadcastStream().map((event) => event as bool);
@override
Stream<bool> get onKeyboardVisibilityChange => _onKeyboardVisibilityChange;
@override
Future<String> getPlatformVersion() async {
String? version = await _methodChannel.invokeMethod<String>(INFRA_UI_METHOD_GET_PLATFORM_VERSION);
return version ?? 'unknow';
}
}

View File

@ -1,4 +1,4 @@
name: keyboard_platform_interface
name: flowy_infra_ui_platform_interface
description: A new Flutter package project.
version: 0.0.1
homepage:
@ -10,7 +10,7 @@ environment:
dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.0.0
dev_dependencies:
@ -18,4 +18,4 @@ dev_dependencies:
sdk: flutter
flutter_lints: ^1.0.0
flutter:
flutter:

View File

@ -0,0 +1,5 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flowy_infra_ui_platform_interface/flowy_infra_ui_platform_interface.dart';
void main() {}

View File

@ -1,4 +1,4 @@
# keyboard_web
# flowy_infra_ui_web
A new Flutter package project.

View File

@ -0,0 +1,23 @@
library flowy_infra_ui_web;
import 'package:flowy_infra_ui_platform_interface/flowy_infra_ui_platform_interface.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
class FlowyInfraUIPlugin extends FlowyInfraUIPlatform {
static void registerWith(Registrar registrar) {
FlowyInfraUIPlatform.instance = FlowyInfraUIPlugin();
}
// MARK: - Keyboard
@override
Stream<bool> get onKeyboardVisibilityChange async* {
// suppose that keyboard won't show in web side
yield false;
}
@override
Future<String?> getPlatformVersion() async {
return 'Web: unknow version';
}
}

View File

@ -50,6 +50,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
flowy_infra_ui_platform_interface:
dependency: "direct main"
description:
path: "../flowy_infra_ui_platform_interface"
relative: true
source: path
version: "0.0.1"
flutter:
dependency: transitive
description: flutter
@ -79,13 +86,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
keyboard_platform_interface:
dependency: "direct main"
description:
path: "../keyboard_platform_interface"
relative: true
source: path
version: "0.0.1"
lints:
dependency: transitive
description:

View File

@ -1,7 +1,8 @@
name: keyboard_web
name: flowy_infra_ui_web
description: A new Flutter package project.
version: 0.0.1
homepage:
publish_to: none
environment:
sdk: ">=2.12.0 <3.0.0"
@ -11,8 +12,8 @@ dependencies:
flutter_web_plugins:
sdk: flutter
keyboard_platform_interface:
path: ../keyboard_platform_interface
flowy_infra_ui_platform_interface:
path: ../flowy_infra_ui_platform_interface
dev_dependencies:
flutter_test:
@ -23,5 +24,5 @@ flutter:
plugin:
platforms:
web:
pluginClass: KeyboardPlugin
fileName: keyboard_web
pluginClass: FlowyInfraUIPlugin
fileName: flowy_infra_ui_web.dart

View File

@ -0,0 +1,5 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flowy_infra_ui_web/flowy_infra_ui_web.dart';
void main() {}

View File

@ -1,23 +0,0 @@
library keyboard_platform_interface;
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'src/method_channel_keyboard.dart';
abstract class KeyboardPlatform extends PlatformInterface {
KeyboardPlatform() : super(token: _token);
static final Object _token = Object();
static KeyboardPlatform _instance = MethodChannelKeyboard();
static KeyboardPlatform get instance => _instance;
static set instance(KeyboardPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
Stream<bool> get onKeyboardChange {
throw UnimplementedError('`onKeyboardChange` should be overrided by subclass.');
}
}

View File

@ -1,17 +0,0 @@
import 'dart:html';
import 'package:flutter/services.dart';
import '../keyboard_platform_interface.dart';
// ignore: constant_identifier_names
const INFRA_UI_KEYBOARD_EVENT_CHANNEL_NAME = "flowy_infra_ui_event/keyboard";
class MethodChannelKeyboard extends KeyboardPlatform {
final EventChannel _keyboardChannel = const EventChannel(INFRA_UI_KEYBOARD_EVENT_CHANNEL_NAME);
late final Stream<bool> _onKeyboardChange = _keyboardChannel.receiveBroadcastStream().map((event) => event as bool);
@override
Stream<bool> get onKeyboardChange => _onKeyboardChange;
}

View File

@ -1,5 +0,0 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:keyboard_platform_interface/keyboard_platform_interface.dart';
void main() {}

View File

@ -1,7 +0,0 @@
library keyboard_web;
/// A Calculator.
class Calculator {
/// Returns [value] plus 1.
int addOne(int value) => value + 1;
}

View File

@ -1,12 +0,0 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:keyboard_web/keyboard_web.dart';
void main() {
test('adds one to input values', () {
final calculator = Calculator();
expect(calculator.addOne(2), 3);
expect(calculator.addOne(-7), -6);
expect(calculator.addOne(0), 1);
});
}

View File

@ -85,6 +85,20 @@ packages:
relative: true
source: path
version: "0.0.1"
flowy_infra_ui_platform_interface:
dependency: "direct main"
description:
path: flowy_infra_ui_platform_interface
relative: true
source: path
version: "0.0.1"
flowy_infra_ui_web:
dependency: "direct main"
description:
path: flowy_infra_ui_web
relative: true
source: path
version: "0.0.1"
flutter:
dependency: "direct main"
description: flutter
@ -103,7 +117,7 @@ packages:
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: "direct main"
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
@ -163,6 +177,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
provider:
dependency: "direct main"
description:

View File

@ -11,8 +11,7 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_web_plugins:
sdk: flutter
# Thirdparty packages
textstyle_extensions: '2.0.0-nullsafety'
dartz: '0.10.0-nullsafety.2'
@ -20,6 +19,13 @@ dependencies:
styled_widget: '>=0.3.1'
equatable: '>=2.0.2'
animations: ^2.0.0
# Federated Platform Interface
flowy_infra_ui_platform_interface:
path: flowy_infra_ui_platform_interface
flowy_infra_ui_web:
path: flowy_infra_ui_web
# Flowy packages
flowy_infra:
path: ../flowy_infra
@ -34,13 +40,12 @@ flutter:
platforms:
android:
package: com.example.flowy_infra_ui
pluginClass: FlowyInfraUiPlugin
pluginClass: FlowyInfraUIPlugin
ios:
pluginClass: FlowyInfraUiPlugin
pluginClass: FlowyInfraUIPlugin
macos:
pluginClass: FlowyInfraUiPlugin
pluginClass: FlowyInfraUIPlugin
windows:
pluginClass: FlowyInfraUiPlugin
pluginClass: FlowyInfraUIPlugin
web:
pluginClass: FlowyInfraUiWeb
fileName: flowy_infra_ui_web.dart
default_package: flowy_infra_ui_web