Skip to content

Commit

Permalink
first experimental execution successful
Browse files Browse the repository at this point in the history
  • Loading branch information
m-r-davari committed Nov 20, 2023
1 parent e05959a commit 9c18291
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
33 changes: 32 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,49 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {

Flutter3DController controller = Flutter3DController();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
FloatingActionButton.small(
onPressed: (){
controller.playAnimation();
},
child: const Icon(Icons.play_arrow),
),
const SizedBox(height: 4,),
FloatingActionButton.small(
onPressed: (){
controller.pauseAnimation();
},
child: const Icon(Icons.pause),
),
const SizedBox(height: 4,),
FloatingActionButton.small(
onPressed: ()async{
final result = await controller.getAvailableAnimations();
print('Anims : $result');
},
child: const Icon(Icons.format_list_bulleted_outlined),
)
],
),
body: Container(
color: Colors.blueAccent,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: const Flutter3DViewer(
child: Flutter3DViewer(
controller: controller,
src: 'assets/dancing_girl.glb',
),
),
Expand Down
14 changes: 7 additions & 7 deletions lib/src/controllers/flutter_3d_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter_3d_controller/src/data/repositories/i_flutter_3d_reposit

class Flutter3DController extends IFlutter3DController with ChangeNotifier {

late IFlutter3DRepository _repository;
IFlutter3DRepository? _repository;
Flutter3DController();

void init(IFlutter3DRepository repository){
Expand All @@ -14,27 +14,27 @@ class Flutter3DController extends IFlutter3DController with ChangeNotifier {

@override
void playAnimation(){
_repository.playAnimation();
_repository?.playAnimation();
}

@override
void pauseAnimation(){
_repository.pauseAnimation();
_repository?.pauseAnimation();
}

@override
Future<List<String>> getAvailableAnimations(){
return _repository.getAvailableAnimations();
Future<List<String>> getAvailableAnimations()async{
return await _repository?.getAvailableAnimations() ?? [];
}

@override
void setCameraOrbit(double theta, double phi, double radius){
_repository.setCameraOrbit(theta,phi,radius);
_repository?.setCameraOrbit(theta,phi,radius);
}

@override
void setCameraTarget(double x, double y, double z){
_repository.setCameraTarget(x,y,z);
_repository?.setCameraTarget(x,y,z);
}

}
6 changes: 4 additions & 2 deletions lib/src/data/datasources/flutter_3d_datasource_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ class Flutter3DDatasource implements IFlutter3DDatasource {

@override
Future<List<String>> getAvailableAnimations() async {
final result = await executeCustomJsCodeWithResult(
print('-------callerx------3');
executeCustomJsCode(
"const modelViewer = document.querySelector(\"model-viewer\");"
"const anims = modelViewer.availableAnimations;"
"console.log(anims);"
);
return result as List<String>;
return [''] ;
}


Expand Down
7 changes: 1 addition & 6 deletions lib/src/data/datasources/i_flutter_3d_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ import 'package:flutter_3d_controller/src/data/datasources/flutter_3d_datasource


abstract class IFlutter3DDatasource{

void playAnimation({String? animationName});
void pauseAnimation();
Future<List<String>> getAvailableAnimations();
void setCameraOrbit(double theta, double phi, double radius);
void setCameraTarget(double x, double y, double z);


// static IFlutter3DDatasource generate (value){
// return Flutter3DDatasource(value);
// }

factory IFlutter3DDatasource(value) => Flutter3DDatasource(value);


}
6 changes: 3 additions & 3 deletions lib/src/widgets/flutter_3d_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import 'package:webview_flutter/webview_flutter.dart';
class Flutter3DViewer extends StatefulWidget {

final String src;
final Flutter3DController? flutter3dController;
final Flutter3DController? controller;

const Flutter3DViewer({Key? key,required this.src,this.flutter3dController,}) : super(key: key);
const Flutter3DViewer({Key? key,required this.src,this.controller,}) : super(key: key);

@override
State<Flutter3DViewer> createState() => _Flutter3DViewerState();
Expand All @@ -23,8 +23,8 @@ class _Flutter3DViewerState extends State<Flutter3DViewer> {

@override
void initState() {
_controller = widget.controller;
super.initState();
_controller == widget.flutter3dController;
}

@override
Expand Down

0 comments on commit 9c18291

Please sign in to comment.