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

FlareActor will run when the The RenderBox detach #23

Open
HaoliangHsiao opened this issue Dec 25, 2018 · 5 comments
Open

FlareActor will run when the The RenderBox detach #23

HaoliangHsiao opened this issue Dec 25, 2018 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@HaoliangHsiao
Copy link

FlareActor will be run when FlareActorRenderObject be detach (not dispose). The schedule need to stop when FlareActorRenderObject detach. Thank you.

@OverRide
void attach(PipelineOwner owner) {
super.attach(owner);
// start schedule
}

@OverRide
void detach() {
super.detach();
// stop schedule
}

@luigi-rosso luigi-rosso self-assigned this Dec 26, 2018
@luigi-rosso luigi-rosso added the bug Something isn't working label Dec 26, 2018
@luigi-rosso
Copy link
Contributor

What's the use case/flow you're using that's triggering a detach but not a dispose? I'd like to be able to test this condition.

Is it related to navigation?

@luigi-rosso
Copy link
Contributor

In the meantime I have pushed a fix for this and have updated the package on pub as well. Please let me know the workflow to trigger a test case for this.

@HaoliangHsiao
Copy link
Author

HaoliangHsiao commented Jan 2, 2019

@luigi-rosso, About this issue. This is flutter behavior.
Pages on Navigator stack rebuild when a new page is pushed#11655
FlareActor will be rebuilding after navigator to another page.
For the performance, The developer needs to pause the FlareActor when going to another page and resume FlareActor when back.

This is Penguin demo.

class _MyHomePageState extends State<MyHomePage> implements FlareController {
  double _rockAmount = 0.5;
  double _speed = 1.0;
  double _rockTime = 0.0;
  bool _isPaused = false;

  ActorAnimation _rock;

  void initialize(FlutterActorArtboard artboard) {
    _rock = artboard.getAnimation("music_walk");
  }

  void setViewTransform(Mat2D viewTransform) {}

  bool advance(FlutterActorArtboard artboard, double elapsed) {
    print("advance ");
    _rockTime += elapsed * _speed;
    _rock.apply(_rockTime % _rock.duration, artboard, _rockAmount);
    return true;
  }

  @override
  void dispose() {
    print("dispose ");
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      backgroundColor: Colors.grey,
      appBar: new AppBar(title: new Text(widget.title)),
      body: new Stack(
        children: [
          Positioned.fill(
              child: FlareActor("assets/Penguin.flr",
                  alignment: Alignment.center,
                  isPaused: _isPaused,
                  fit: BoxFit.cover,
                  animation: "walk",
                  controller: this)),
          Positioned.fill(
              child: new Column(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[
                Container(
                    height: 220,
                    color: Colors.black.withOpacity(0.5),
                    child: new Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        new Text("Mix Amount",
                            style: TextStyle(color: Colors.white)),
                        new Slider(
                          value: _rockAmount,
                          min: 0.0,
                          max: 1.0,
                          divisions: null,
                          onChanged: (double value) {
                            setState(() {
                              _rockAmount = value;
                            });
                          },
                        ),
                        new Text("Speed",
                            style: TextStyle(color: Colors.white)),
                        new Slider(
                          value: _speed,
                          min: 0.2,
                          max: 3.0,
                          divisions: null,
                          onChanged: (double value) {
                            setState(() {
                              _speed = value;
                            });
                          },
                        ),
                        new Text("Paused",
                            style: TextStyle(color: Colors.white)),
                        new Checkbox(
                          value: _isPaused,
                          onChanged: (bool value) {
                            setState(() {
                              _isPaused = value;
                            });
                          },
                        ),
                        Padding(
                          padding: EdgeInsets.only(left: 10.0),
                          child: RaisedButton(
                            onPressed: () {
                              _isPaused = true;
                              _openPage();
                            },
                            child: Text("Next Page"),
                          ),
                        )
                      ],
                    )),
              ]))
        ],
      ),
    );
  }

  _openPage() async {
    var result = await Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => NextPage()),
    );
    _isPaused = false;
  }
}

@luigi-rosso
Copy link
Contributor

Thanks for the example! Are still seeing this issue with the latest Flare-Flutter update?

@HaoliangHsiao
Copy link
Author

@luigi-rosso, This issue still happened on Flutter v1.1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants