Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change obj file runtime #19

Closed
jaydangar opened this issue Jul 24, 2020 · 0 comments
Closed

Change obj file runtime #19

jaydangar opened this issue Jul 24, 2020 · 0 comments

Comments

@jaydangar
Copy link

Hello and first of all thank you for the great package for making the 3d rendering easy on flutter. I have found a little bug through, I am using flutter_bloc and want to change object while I toggle between options, I have my code, but it isn't changing the obj file. can you look into the matter? This is my code.

import 'package:cube/bloc/switch_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_3d_obj/flutter_3d_obj.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool switchState = false;
  double rating = 300;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Cube'),
      ),
      body: BlocProvider(
        create: (context) => SwitchBloc(),
        child: Container(
          color: Colors.white,
          child: Column(children: [
            Expanded(
              flex: 9,
              child: BlocBuilder<SwitchBloc, SwitchState>(
                builder: (BuildContext context, state) {
                  if (state is SwitchChanged) {
                    if (state.switchState) {
                      return CenterWidget(
                          modelSource: 'assets/cube/cube.obj', rating: rating);
                    } else {
                      return CenterWidget(
                          modelSource: 'assets/wired_cube/wired_cube.obj',
                          rating: rating);
                    }
                  }
                  return CenterWidget(
                      modelSource: 'assets/wired_cube/wired_cube.obj',
                      rating: rating);
                },
              ),
            ),
            Divider(),
            Expanded(
              flex: 3,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                      Text('Wire'),
                      BlocBuilder<SwitchBloc, SwitchState>(
                        builder: (context, state) {
                          bool switchVal;
                          if (state is SwitchInitial) {
                            switchVal = state.switchState;
                          } else if (state is SwitchChanged) {
                            switchVal = state.switchState;
                          }
                          return Switch(
                            value: switchVal,
                            onChanged: (value) =>
                                BlocProvider.of<SwitchBloc>(context).add(
                              OnSwitchPressed(switchValue: switchVal),
                            ),
                          );
                        },
                      ),
                      Text('Solid')
                    ],
                  ),
                  Slider(
                    value: rating,
                    onChanged: (value) => setState(() {
                      rating = value;
                    }),
                    min: 300,
                    max: 1200,
                  ),
                ],
              ),
            ),
          ]),
        ),
      ),
    );
  }
}

class CenterWidget extends StatelessWidget {
  const CenterWidget({
    Key key,
    @required this.modelSource,
    @required this.rating,
  }) : super(key: key);

  final String modelSource;
  final double rating;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Object3D(
        size: Size(30, 30),
        path: modelSource,
        asset: true,
        zoom: rating,
      ),
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant