first commit
This commit is contained in:
58
lib/view/filament_view.dart
Normal file
58
lib/view/filament_view.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../filament_controller.dart';
|
||||
import 'filament_view_platform.dart';
|
||||
|
||||
class FilamentView extends FilamentViewPlatform {
|
||||
static const FILAMENT_VIEW_ID = 'mimetic.app/filament_view';
|
||||
|
||||
@override
|
||||
Widget buildView(
|
||||
int creationId,
|
||||
FilamentViewCreatedCallback onFilamentViewCreated,
|
||||
) {
|
||||
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();
|
||||
},
|
||||
);
|
||||
case TargetPlatform.iOS:
|
||||
return UiKitView(
|
||||
viewType: FILAMENT_VIEW_ID,
|
||||
onPlatformViewCreated: (int id) {
|
||||
onFilamentViewCreated(id);
|
||||
},
|
||||
);
|
||||
default:
|
||||
return Text(
|
||||
'$defaultTargetPlatform is not yet implemented by Filament plugin.');
|
||||
}
|
||||
}
|
||||
}
|
||||
22
lib/view/filament_view_platform.dart
Normal file
22
lib/view/filament_view_platform.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:mimetic_filament/view/filament_view.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
import '../../filament_controller.dart';
|
||||
|
||||
typedef void FilamentViewCreatedCallback(int id);
|
||||
|
||||
abstract class FilamentViewPlatform extends PlatformInterface {
|
||||
FilamentViewPlatform() : super(token: _token);
|
||||
|
||||
static final Object _token = Object();
|
||||
static FilamentViewPlatform _instance = FilamentView();
|
||||
|
||||
static FilamentViewPlatform get instance => _instance;
|
||||
|
||||
Widget buildView(
|
||||
int creationId,
|
||||
FilamentViewCreatedCallback onFilamentViewCreated,
|
||||
) {
|
||||
throw UnimplementedError('buildView() has not been implemented.');
|
||||
}
|
||||
}
|
||||
25
lib/view/filament_widget.dart
Normal file
25
lib/view/filament_widget.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../filament_controller.dart';
|
||||
import 'filament_view_platform.dart';
|
||||
|
||||
int _nextFilamentCreationId = 0;
|
||||
|
||||
class FilamentWidget extends StatefulWidget {
|
||||
final FilamentController controller;
|
||||
|
||||
const FilamentWidget({Key? key, required this.controller}) : super(key: key);
|
||||
|
||||
@override
|
||||
_FilamentWidgetState createState() => _FilamentWidgetState();
|
||||
}
|
||||
|
||||
class _FilamentWidgetState extends State<FilamentWidget> {
|
||||
final _viewId = _nextFilamentCreationId++;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FilamentViewPlatform.instance
|
||||
.buildView(_viewId, widget.controller.onFilamentViewCreated);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user