Flutter 在有状态小部件中传递密钥时出错

Flutter 在有状态小部件中传递密钥时出错,flutter,statefulwidget,Flutter,Statefulwidget,我正在尝试设置AnimatedContainer宽度的动画。为此,我在外部文件中使用了一个statefull小部件,下面是这个类的代码 class AnimatedContainerWidget extends StatefulWidget { const AnimatedContainerWidget({ Key: key, }) : super(key: key); @override _AnimatedContainerWidgetState createState()

我正在尝试设置AnimatedContainer宽度的动画。为此,我在外部文件中使用了一个statefull小部件,下面是这个类的代码

class AnimatedContainerWidget extends StatefulWidget {
const AnimatedContainerWidget({
    Key: key,
  }) : super(key: key);
  @override
  _AnimatedContainerWidgetState createState() =>
      _AnimatedContainerWidgetState();
}

class _AnimatedContainerWidgetState extends State<AnimatedContainerWidget> {
  double _height = 100.0;
  double _width = 100.0;
  _increaseWidth() {
    setState(() {
      _width = _width >= 300 ? 100.0 : _width += 50.0;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        AnimatedContainer(
          duration: Duration(milliseconds: 500),
          curve: Curves.elasticInOut,
          color: Colors.amber,
          height: _height,
          width: _width,
          child: FlatButton(
            child: Text('Tap to grow width\n $_width'),
            onPressed: _increaseWidth(),
          ),
        )
      ],
    );
  }
}

构造函数中有一个冒号需要删除

const AnimatedContainerWidget({
Key Key,//将“Key:Key”替换为“Key”
}):super(key:key);
这样写

 AnimatedContainerWidget({Key key, this.image}) : super(key: key);
 AnimatedContainerWidget({Key key, this.image}) : super(key: key);