add android integration & make iOS API consistent
add pubspec android plugin update android CMakeLists add filament android libs for linking
This commit is contained in:
@@ -4,7 +4,6 @@ import 'package:flutter/services.dart';
|
||||
|
||||
abstract class FilamentController {
|
||||
void onFilamentViewCreated(int id);
|
||||
|
||||
Future loadSkybox(String skyboxPath, String lightingPath);
|
||||
Future loadGlb(String path);
|
||||
Future loadGltf(String path, String relativeResourcePath);
|
||||
@@ -43,23 +42,15 @@ class PolyvoxFilamentController extends FilamentController {
|
||||
_id = id;
|
||||
_channel = MethodChannel("app.polyvox.filament/filament_view_$id");
|
||||
_channel.setMethodCallHandler((call) async {
|
||||
await Future.delayed(const Duration(
|
||||
seconds:
|
||||
1)); // todo - need a better way to know when the GL context is actually ready
|
||||
await _initialize();
|
||||
onFilamentViewCreatedHandler?.call(_id);
|
||||
return Future.value(true);
|
||||
if(call.method == "ready") {
|
||||
onFilamentViewCreatedHandler?.call(_id);
|
||||
return Future.value(true);
|
||||
} else {
|
||||
throw Exception("Unknown method channel invocation ${call.method}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Future _initialize() async {
|
||||
await _channel.invokeMethod("initialize", [
|
||||
"packages/polyvox_filament/assets/lit_opaque.filamat",
|
||||
"packages/polyvox_filament/assets/lit_fade.filamat"
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
Future loadSkybox(String skyboxPath, String lightingPath) async {
|
||||
await _channel.invokeMethod("loadSkybox", [skyboxPath, lightingPath]);
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
// You have generated a new plugin project without
|
||||
// specifying the `--platforms` flag. A plugin project supports no platforms is generated.
|
||||
// To add platforms, run `flutter create -t plugin --platforms <platforms> .` under the same
|
||||
// directory. You can also find a detailed instruction on how to add platforms in the `pubspec.yaml` at https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class PolyvoxFilament {
|
||||
static const MethodChannel _channel = MethodChannel('polyvox_filament');
|
||||
|
||||
static Future<String?> get platformVersion async {
|
||||
final String? version = await _channel.invokeMethod('getPlatformVersion');
|
||||
return version;
|
||||
}
|
||||
}
|
||||
@@ -17,32 +17,14 @@ class FilamentView extends FilamentViewPlatform {
|
||||
) {
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.android:
|
||||
return PlatformViewLink(
|
||||
viewType: FILAMENT_VIEW_ID,
|
||||
surfaceFactory:
|
||||
(BuildContext context, PlatformViewController controller) {
|
||||
return AndroidViewSurface(
|
||||
controller: controller as AndroidViewController,
|
||||
gestureRecognizers: const <
|
||||
Factory<OneSequenceGestureRecognizer>>{},
|
||||
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
|
||||
);
|
||||
},
|
||||
onCreatePlatformView: (PlatformViewCreationParams params) {
|
||||
return PlatformViewsService.initSurfaceAndroidView(
|
||||
id: params.id,
|
||||
viewType: FILAMENT_VIEW_ID,
|
||||
layoutDirection: TextDirection.ltr,
|
||||
creationParams: {},
|
||||
creationParamsCodec: StandardMessageCodec(),
|
||||
)
|
||||
..addOnPlatformViewCreatedListener((int id) {
|
||||
onFilamentViewCreated(id);
|
||||
params.onPlatformViewCreated(id);
|
||||
})
|
||||
..create();
|
||||
},
|
||||
);
|
||||
return AndroidView(
|
||||
viewType: FILAMENT_VIEW_ID,
|
||||
gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{},
|
||||
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
|
||||
onPlatformViewCreated: (id) {
|
||||
print("onplatformview created $id");
|
||||
onFilamentViewCreated(id);
|
||||
});
|
||||
case TargetPlatform.iOS:
|
||||
return UiKitView(
|
||||
viewType: FILAMENT_VIEW_ID,
|
||||
@@ -51,8 +33,7 @@ class FilamentView extends FilamentViewPlatform {
|
||||
},
|
||||
);
|
||||
case TargetPlatform.windows:
|
||||
return Text(
|
||||
"Flutter doesn't support platform view on Windows yet.");
|
||||
return Text("Flutter doesn't support platform view on Windows yet.");
|
||||
default:
|
||||
return Text(
|
||||
'$defaultTargetPlatform is not yet implemented by Filament plugin.');
|
||||
|
||||
@@ -2,13 +2,13 @@ import 'package:flutter/widgets.dart';
|
||||
import 'package:polyvox_filament/view/filament_view.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
typedef void FilamentViewCreatedCallback(int id);
|
||||
typedef FilamentViewCreatedCallback = void Function(int id);
|
||||
|
||||
abstract class FilamentViewPlatform extends PlatformInterface {
|
||||
FilamentViewPlatform() : super(token: _token);
|
||||
|
||||
static final Object _token = Object();
|
||||
static FilamentViewPlatform _instance = FilamentView();
|
||||
static final FilamentViewPlatform _instance = FilamentView();
|
||||
|
||||
static FilamentViewPlatform get instance => _instance;
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:polyvox_filament/view/filament_view.dart';
|
||||
|
||||
import '../filament_controller.dart';
|
||||
import 'filament_view_platform.dart';
|
||||
|
||||
Reference in New Issue
Block a user