Open Ahadu-ray opened 6 months ago
Same in my case. change src or variantName does nothing.
I found out some workaround. It's not ideal but for some application will be ok. setState not refresh ModelViewer. To force it you can add key to ModelViewer and change this key when you want change some variable. it's work with everything but it not change it smootly. so for example when you change cameraTarget then your model disappear and appear with new cameraTarget.
class SamplePage extends StatefulWidget{
const SamplePage({super.key});
@override
State<SamplePage > createState() => _SamplePageState();
}
class _SamplePageState extends State<SamplePage>{
String _src = 'oldModelSrc';
Key _refreshKey = UniqueKey();
@override
Widget build(BuildContext context){
return Scaffold(
body: Column(
children:[
ElevatedButton(
onPressed: () => setState(() {
_src = 'newModelSrc';
_refreshKey = UniqueKey();
}),
child: const Text('New Model'),
),
ModelViewer(
key: _refreshKey,
src: _src,
)
]
)
)
}
}
The state of the model_viewer doesn't change when a parameter is changed. For instance, the model being displayed is not updated when the src parameter's value is changed via setState or with state management tooks