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

多张图片双击启用动画放大滑动下一张后再双击抛异常 #3

Closed
figbin opened this issue Apr 24, 2019 · 1 comment
Closed

Comments

@figbin
Copy link

figbin commented Apr 24, 2019

复现步骤:
1、进入ExtendedImageGesturePageView 默认打开第一张图initialPage=0。双击缩放,再双击缩小,无问题。
2、滑动到下一页 initialPage=1,双击缩放,抛弃常。
3、如果 itemBuilder: (context, position) { 不返回 ExtendedImage.asset 而直接使用原生 Image 动画正常,不抛弃常。

AnimationController.stop() called after AnimationController.dispose()
flutter: When the exception was thrown, this was the stack:
flutter: #2      AnimationController.stop (package:flutter/src/animation/animation_controller.dart:698:7)
flutter: #3      GestureAnimation.stop (package:extended_image/src/gesture/extended_image_gesture_utils.dart:369:24)
flutter: #4      _ExtendedImageGestureState._handleScaleStart (package:extended_image/src/gesture/extended_image_gesture.dart:77:23)
flutter: #5      _ExtendedImageGestureState.handleDoubleTap (package:extended_image/src/gesture/extended_image_gesture.dart:247:5)
flutter: #6      _My.build.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:testapp/my.dart:72:27)

完整代码:

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


class My extends StatefulWidget {

  @override
  _My createState() => _My();
}

class _My extends State<My> with SingleTickerProviderStateMixin {
  AnimationController _animationController;
  Animation<double> _animation;

  @override
  void initState() {
    super.initState();
    _animationController = AnimationController(duration: Duration(milliseconds: 100), vsync: this);
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    List<String> files = ["a.jpg", "b.jpg", 'c.jpg'];
    PageController pageController = PageController();

    return ExtendedImageGesturePageView.builder(
        controller: pageController,
        onPageChanged: (int index){
          print('onPageChanged');
        },
        itemCount: 3,
        itemBuilder: (context, position) {
          var file = files[position];
          return Container(
              child: ExtendedImage.asset(
              "assets/images/$file",
              fit: BoxFit.contain,
              //enableLoadState: false,
              mode: ExtendedImageMode.Gesture,
              gestureConfig: GestureConfig(
                  minScale: 0.9,
                  animationMinScale: 0.7,
                  maxScale: 3.0,
                  animationMaxScale: 3.5,
                  speed: 1.0,
                  inertialSpeed: 100.0,
                  initialScale: 1.0,
                  inPageView: true
              ),
              onDoubleTap: (ExtendedImageGestureState state) {
                double begin = 0.0;
                double end = 0.0;
                if (state.gestureDetails.totalScale == 1.0) {
                  begin = 1.0;
                  end = 2.0;
                } else {
                  begin = state.gestureDetails.totalScale;
                  end = 1.0;
                }

                // PageView: Another exception was thrown: AnimationController.stop() called after AnimationController.dispose()
                try {
                  _animationController.reset();
                  _animation = Tween<double>(begin: begin, end: end).animate(_animationController);
                  _animation.addListener((){
                    state.handleDoubleTap(scale: _animation.value, doubleTapPosition: state.pointerDownPosition);
                  });
                  _animationController.forward();
                }catch(e){
                  print('xxxx');
                }
              }
            )
          );
        });
  }

}

@zmtzawqlp
Copy link
Member

zmtzawqlp commented Apr 24, 2019

@figbin
fix with 59ed7be, please update version 0.3.0, let me konw if it's fixed.

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

2 participants