MarlonJD / babylonjs_viewer

Flutter 3D Model Viewer with BabylonJS Viewer
MIT License
27 stars 10 forks source link

the viewer doesnt refresh its content #6

Closed manpowre closed 1 year ago

manpowre commented 2 years ago

I think its because the underlaying webview doesnt have a controller.

Could we mabye get reloadmodel function into this plugin? , and use a controller within the webview, I think that should do it.

I have testcode here, just add 2 .glb files to assets.:

import 'package:flutter/material.dart'; import 'package:babylonjs_viewer/babylonjs_viewer.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter DropDownButton', theme: ThemeData( primarySwatch: Colors.green, ), home: const MyHomePage(), debugShowCheckedModeBanner: false, ); } }

class MyHomePage extends StatefulWidget { const MyHomePage({Key? key}) : super(key: key);

@override _MyHomePageState createState() => _MyHomePageState(); }

class _MyHomePageState extends State { String dropdownvalue = 'assets/test1.glb'; late BabylonJSViewer bsv;

@override void initState() {

super.initState();
bsv = BabylonJSViewer(
  src: dropdownvalue,
);

}

var items2 = [ 'assets/test1.glb', 'assets/alpha-blend-litmus.glb', ];

@override Widget build(BuildContext context) { bsv = BabylonJSViewer( src: dropdownvalue, );

return Scaffold(
  appBar: AppBar(
    title: const Text("3d models"),
  ),
  body: Center(
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        DropdownButton(
          value: dropdownvalue,
          icon: const Icon(Icons.keyboard_arrow_down),
          items: items2.map((String items2) {
            return DropdownMenuItem(
              value: items2,
              child: Text(items2),
            );
          }).toList(),
          onChanged: (String? newValue) {
            setState(() {
              dropdownvalue = newValue!;

              bsv = BabylonJSViewer(
                src: newValue,
              );

              print(dropdownvalue);
            });
          },
        ),
        Expanded(child: bsv),
      ],
    ),
  ),
);

} }

MarlonJD commented 2 years ago

Did you test the code? You can create pull request

manpowre commented 2 years ago

I made this code mentioned here. its just a dropdown changing the value/model in assets, and setting initstate. But the 3dviewer doesnt change.

as far as I could read webview needs a controller, and with that this viewer could get a reload model with a new src string.

MarlonJD commented 2 years ago

I didn't have much time for this, so i create page with model argument, and go to that page again with link argument. That's the easiest way