Skip to content

Instantly share code, notes, and snippets.

@frantovar
Created January 19, 2023 19:35
Show Gist options
  • Save frantovar/5beb39a1d5a36bfa3033998e26c17c0f to your computer and use it in GitHub Desktop.
Save frantovar/5beb39a1d5a36bfa3033998e26c17c0f to your computer and use it in GitHub Desktop.
ModelViewer with a dialog
class Viewer3DView extends StatelessWidget {
const Viewer3DView({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('3D Model'),
actions: [
IconButton(
onPressed: () => _dialogBuilder(context),
icon: const Icon(Icons.info_outlined),
)
],
),
body: ModelViewer(
id: 'MyModel',
src: 'https://modelviewer.dev/shared-assets/models/shishkebab.glb',
),
);
}
Future<void> _dialogBuilder(BuildContext context) {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Holly Dolly'),
content: const Text(
'Closing this dialog will broke model rotation controlls'),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment