playx-flutter / playx-3d-scene

Plugin for showing 3d models in flutter (Only Android)
MIT License
3 stars 1 forks source link

platform view initialization error #31

Closed AttalliAyoub closed 1 year ago

AttalliAyoub commented 1 year ago

What is the problem? the widget can't initialize because of an error creating the PlatformView of the plugin

and this is the code I have:

`import 'package:flutter/material.dart'; import 'package:playx_3d_scene/controller/playx_3d_scene_controller.dart'; import 'package:playx_3d_scene/models/model/glb_model.dart'; import 'package:playx_3d_scene/models/scene/indirect_light/hdr_indirect_light.dart'; import 'package:playx_3d_scene/models/scene/scene.dart'; import 'package:playx_3d_scene/models/scene/skybox/hdr_skybox.dart'; import 'package:playx_3d_scene/models/state/model_state.dart'; import 'package:playx_3d_scene/view/playx_3d_scene.dart';

class HomePage extends StatefulWidget { const HomePage({super.key});

@override State createState() => _HomePageState(); }

class _HomePageState extends State { bool loading = true;

jqsmflk() { Scene(); }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Ayoub 3D Test'), ), body: Playx3dScene( model: GlbModel.asset( "assets/t_shirt.glb", // animation: PlayxAnimation.byIndex(0, autoPlay: true), ), scene: Scene( skybox: HdrSkybox.asset("assets/studio_small_02_4k.hdr"), // indirectLight: // HdrIndirectLight.asset("assets/envs/courtyard.hdr"), ), onCreated: (Playx3dSceneController controller) async { // await controller.changeAnimationByIndex(1); print(controller); }, onModelStateChanged: (state) { setState(() { loading = state == ModelState.loading; }); }, ), ); } }`

this is the logs:

Launching lib\main.dart on AOSP on IA Emulator in debug mode... ✓ Built build\app\outputs\flutter-apk\app-debug.apk. Connecting to VM Service at ws://127.0.0.1:54487/BbCkuX9JCXo=/ws D/eglCodecCommon(17485): setVertexArrayObject: set vao to 0 (0) 1 0 D/EGL_emulation(17485): eglMakeCurrent: 0xde770aa0: ver 2 0 (tinfo 0xc9a60fa0) E/flutter (17485): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: io.sourcya.playx.3d.scene.channel_3d_scene E/flutter (17485): at io.flutter.plugin.platform.PlatformViewsController.createPlatformView(PlatformViewsController.java:496) E/flutter (17485): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:191) E/flutter (17485): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:128) E/flutter (17485): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:55) E/flutter (17485): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258) E/flutter (17485): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/flutter (17485): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322) E/flutter (17485): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/flutter (17485): at android.os.Handler.handleCallback(Handler.java:873) E/flutter (17485): at android.os.Handler.dispatchMessage(Handler.java:99) E/flutter (17485): at android.os.Looper.loop(Looper.java:193) E/flutter (17485): at android.app.ActivityThread.main(ActivityThread.java:6669) E/flutter (17485): at java.lang.reflect.Method.invoke(Native Method) E/flutter (17485): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) E/flutter (17485): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) E/flutter (17485): , null, null) E/flutter (17485): #0 StandardMethodCodec.decodeEnvelope E/flutter (17485): #1 MethodChannel._invokeMethod E/flutter (17485): E/flutter (17485): #2 TextureAndroidViewController._sendCreateMessage E/flutter (17485): E/flutter (17485): #3 AndroidViewController.create E/flutter (17485): E/flutter (17485): #4 AndroidViewController.setSize E/flutter (17485): E/flutter (17485): #5 RenderAndroidView._sizePlatformView E/flutter (17485): E/flutter (17485):

basemosama commented 1 year ago

Hello, I tested the code and couldn't reproduce the error as the plugin worked as expected.

Can You try running the following

1. flutter clean
2. flutter run

And make sure your minSdkVersion is greater than 23 and try again.