Flutter 如何在flatter中使用AnimatedList小部件

Flutter 如何在flatter中使用AnimatedList小部件,flutter,dart,flutter-animation,flutter-animatedlist,Flutter,Dart,Flutter Animation,Flutter Animatedlist,我看到了这个 我正在尝试实现一个动画列表 但我对动画不是很熟悉 我应该插入什么作为 位置:animation.drive() 及 removietem(_index,(context,animation)=>///我应该做什么 在这里 ),); 下面是代码(只是“启动应用程序”中的一些更改) 有人能帮忙吗 是只缺了这一块还是我缺了别的什么 先谢谢你 [编辑:显示消息 此页面已弃用,其内容可能已过期 事实上,似乎根本没有使用这个小部件]我找到了问题的答案 您可以在这里找到我的代码-->Contai

我看到了这个

我正在尝试实现一个动画列表

但我对动画不是很熟悉

我应该插入什么作为

位置:animation.drive()

removietem(_index,(context,animation)=>///我应该做什么 在这里 ),);

下面是代码(只是“启动应用程序”中的一些更改)

有人能帮忙吗

是只缺了这一块还是我缺了别的什么

先谢谢你

[编辑:显示消息


此页面已弃用,其内容可能已过期


事实上,似乎根本没有使用这个小部件]

我找到了问题的答案

您可以在这里找到我的代码-->Container();//我应该在这里做什么 _列表.删除(_索引); } @凌驾 小部件构建(构建上下文){ 返回脚手架( appBar:appBar( 标题:文本(widget.title), ), 正文:中( 子:动画列表( 键:_listKey, initialItemCount:0, itemBuilder:(构建上下文、int索引、动画){ 返回_buildItem(_list[index].toString(),动画); },), ), 浮动操作按钮:行( mainAxisAlignment:mainAxisAlignment.end, crossAxisAlignment:crossAxisAlignment.end, 儿童:[ 纵队( mainAxisAlignment:mainAxisAlignment.end, crossAxisAlignment:crossAxisAlignment.end, 儿童:[ 浮动操作按钮( 按下时:()=>\u addItem(), 工具提示:“增量”, 子:图标(Icons.add), 浮动操作按钮( 按下时:()=>\u removietem(), 工具提示:“减量”, 子:图标(Icons.remove), ],), ],), ); } 小部件构建项(字符串项、动画项、动画项){ 返回大小转换( sizeFactor:_动画, 孩子:卡片( 孩子:ListTile( 标题:正文( _项目,, ), ), ), ); } }
e.g code-“此页面已弃用,其内容可能已过时。”(事实上,用户不使用animatedList小部件,他们只是以这种方式调用小部件)
      class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

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

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  List<int> _list = [];
  final GlobalKey<AnimatedListState> _listKey = GlobalKey<AnimatedListState>();


  void _addItem() {
    final int _index = _list.length;
    _list.insert(_index,_index);
    _listKey.currentState.insertItem(_index);
  }

  void _removeItem() {
    final int _index = _list.length-1;
    _listKey.currentState.removeItem(_index,(context,animation)=>  /// what I'm supposed to do here
    ),);
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(

        child: AnimatedList(
          key: _listKey,
          initialItemCount: 0,
          itemBuilder: (BuildContext context, int index, Animation animation) {
            return SlideTransition(
              position: animation.drive(
                  /// what I'm supposed to do here
           ),
              child: Card(child: Text(_list[index].toString()),));
          },),
      ),
      floatingActionButton: Column(children: <Widget>[
         FloatingActionButton(
          onPressed:()=> _addItem(),
          tooltip: 'Increment',
          child: Icon(Icons.add),),
        FloatingActionButton(
          onPressed: ()=>_removeItem(),
          tooltip: 'Decrement',
          child: Icon(Icons.remove),),
      ],), 
    );
  }
}
SlideTransition(
                position: Tween<Offset>(
                  begin: const Offset(-1, 0),
                  end: Offset.zero,
                ).animate(animation),
 SlideTransition(
                  position: animation.drive(
                      // what i supposed to go here ??
                  ),
    class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  List<int> _list = [];
  final GlobalKey<AnimatedListState> _listKey = GlobalKey<AnimatedListState>();


  void _addItem() {
    final int _index = _list.length;
    _list.insert(_index,_index);
    _listKey.currentState.insertItem(_index);
  }

  void _removeItem() {
    final int _index = _list.length-1;
    _listKey.currentState.removeItem(_index,(context,animation)=> Container()); /// what I'm supposed to do here
    _list.removeAt(_index);
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(

        child: AnimatedList(
          key: _listKey,
          initialItemCount: 0,
          itemBuilder: (BuildContext context, int index, Animation animation) {
            return _buildItem(_list[index].toString(),animation);
          },),
      ),
      floatingActionButton: Row(
        mainAxisAlignment: MainAxisAlignment.end,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: <Widget>[
          Column(
          mainAxisAlignment: MainAxisAlignment.end,
          crossAxisAlignment: CrossAxisAlignment.end,
          children: <Widget>[
          FloatingActionButton(
            onPressed:()=> _addItem(),
            tooltip: 'Increment',
            child: Icon(Icons.add),),
          FloatingActionButton(
            onPressed: ()=>_removeItem(),
            tooltip: 'Decrement',
            child: Icon(Icons.remove),),
        ],),
      ],), 
    );
  }

  Widget _buildItem(String _item, Animation _animation) {
    return SizeTransition(
      sizeFactor: _animation,
      child: Card(
        child: ListTile(
          title: Text(
            _item,
          ),
        ),
      ),
    );
  }
}