如何在颤抖中延迟列表项?

时间:2018-07-02 19:13:10

标签: flutter flutter-animation

我正在尝试生成一个颤动的列表,该列表会在延迟一段时间后延迟每个项目。 我尝试使用FutureBuilderAnimatedList,但我没有得到它。

import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Example(),
    );
  }
}

class Example extends StatefulWidget {
  @override
  _ExampleState createState() => new _ExampleState();
}

class _ExampleState extends State<Example> with TickerProviderStateMixin{
  AnimationController listViewController;
  final Animation listView;
  Duration duration = new Duration(seconds: 3);
  Timer _timer;

  @override
  void initState() {
    listViewController = new AnimationController(
        duration: new Duration(seconds: 2),
        vsync: this
    );
    super.initState();
  }

  FlutterLogoStyle _logoStyle = FlutterLogoStyle.markOnly;
  item() {
    _timer = new Timer(const Duration(seconds: 1), () {
      return Text("cdscs");
    });
  }

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

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          title: new Text("hello"),
        ),
        // ListView Builder
        body: AnimatedList(
          initialItemCount: 10,
          itemBuilder: (BuildContext context,
              int index,
              Animation<double> animation){
            return item();
          },
        )
    );
  }
}

2 个答案:

答案 0 :(得分:2)

您可以为每个孩子使用metadata:[AVMetadataItem]nil,例如以下示例:

AnimationController

您可以更改动画,在这种情况下,我使用的是Animation模拟淡入淡出的动画。

答案 1 :(得分:1)

也许您可以检查以下回复:https://stackoverflow.com/a/59121771/9481448

for (var i = 0; i < fetchedList.length; i++) {
 future = future.then((_) {
  return Future.delayed(Duration(milliseconds: 100), () {
     // add/remove item
   });
 });