states_rebuilder icon indicating copy to clipboard operation
states_rebuilder copied to clipboard

implicit animation is skipped if parent widget calls setState

Open altynbek132 opened this issue 2 years ago • 4 comments

video:

https://user-images.githubusercontent.com/48729942/163563833-59af7c20-6549-4a14-b6d1-6cae9a9cf24a.mp4

import 'package:flutter/material.dart';
import 'package:states_rebuilder/states_rebuilder.dart';

class DemoScreen extends StatefulWidget {
  const DemoScreen({
    Key? key,
  }) : super(key: key);

  @override
  State<DemoScreen> createState() => _DemoScreenState();
}

class _DemoScreenState extends State<DemoScreen> {
  double height = 100;

  void toggleHeight() {
    height = height == 100 ? 50 : 100;
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    final animation = RM.injectAnimation(
      duration: const Duration(seconds: 1),
      curve: Curves.linear,
    );

    return Scaffold(
      body: ListView(
        children: [
          SizedBox(height: 40),
          TextButton(
            child: Text('toggle'),
            onPressed: toggleHeight,
          ),
          TextButton(
            child: Text('setState(() {});'),
            onPressed: () {
              print('setState(() {});');
              setState(() {});
            },
          ),
          OnAnimationBuilder(
            listenTo: animation,
            builder: (animate) {
              final height = animate(this.height)!;
              return Container(
                height: height,
                width: 50,
                color: Colors.blue,
              );
            },
          ),
        ],
      ),
    );
  }
}

altynbek132 avatar Apr 15 '22 11:04 altynbek132

Hi @altynbek132 Do not define injectAnimation inside the build method.

GIfatahTH avatar Apr 17 '22 14:04 GIfatahTH

@GIfatahTH did not help

altynbek132 avatar Apr 17 '22 16:04 altynbek132

@altynbek132 So Sorry for my lateness; This is a bug and it is fixed.

GIfatahTH avatar May 02 '22 00:05 GIfatahTH

Check version 6.1.0 the bug is fixed.

GIfatahTH avatar May 09 '22 19:05 GIfatahTH