你如何摆脱

时间:2018-06-01 16:01:51

标签: flutter

您好我正在尝试实现卡片翻转动画。 根据以下代码有三张卡。我收到了一个错误 的的NoSuchMethodError 方法'/'在null上调用。 接收器:空 尝试呼叫:/(0.333333333)

代码

class _CardFlipperState extends State<CardFlipper> {
double scrollPercent;
Offset startDrag;
double startDragPercentScroll;
double finishScrollStart;
double finishScrollEnd;
AnimationController finishScrollController;

void _onHorizontalDragStart(DragStartDetails details) {
startDrag = details.globalPosition;
startDragPercentScroll = scrollPercent;
}

void _onHorizontalDragUpdate(DragUpdateDetails details) {
final currDrag = details.globalPosition;
final dragDistance = currDrag.dx - startDrag.dx;
final singleCardDragPercent = dragDistance / context.size.width;

final numCards = 3;

setState(() {
  scrollPercent =
      (startDragPercentScroll + (singleCardDragPercent / numCards))
          .clamp(0.0, 1.0 - (1 / numCards));
 });
 }

 void _onHorizontalDragEnd(DragEndDetails details) {


 setState(() {
  startDrag = null;
  startDragPercentScroll = null;
  });
  }

  List<Widget> _buildCards() {
  return [
  _buildCard(0, 3, scrollPercent),
  _buildCard(1, 3, scrollPercent),
  _buildCard(2, 3, scrollPercent),

   ];
   }

   Widget _buildCard(int cardIndex, int cardCount, double scrollPercent) {
   final cardScrollPercent = scrollPercent / (1 / cardCount);

最后一行似乎是问题我只是弄清楚原因。 我是扑克的新人

2 个答案:

答案 0 :(得分:0)

scrollPercent未初始化,请使用某些内容进行初始化。在最后一行,飞镖最终试图评估null / 1 / 3

答案 1 :(得分:0)

Actually, you are correct. I had not quite gotten what you meant by initialising scrollPercent . Your answer is correct. Thank You