Flutter 使用定时器平滑变化的背景图像

Flutter 使用定时器平滑变化的背景图像,flutter,Flutter,我想以不同资产的路径作为背景来实现和数组。 计时器工作正常,但问题是没有平稳过渡。 我不知道为什么有时候才管用。我知道FadeInImage通常用于等待网络图像,也许这就是问题所在。 有没有其他方法可以达到这个目标 @override void initState(){ super.initState(); timer = Timer.periodic(Duration(seconds: 10), (timer) { setState(() { posb

我想以不同资产的路径作为背景来实现和数组。 计时器工作正常,但问题是没有平稳过渡。 我不知道为什么有时候才管用。我知道FadeInImage通常用于等待网络图像,也许这就是问题所在。 有没有其他方法可以达到这个目标

 @override
  void initState(){
    super.initState();
    timer = Timer.periodic(Duration(seconds: 10), (timer) {
    setState(() {
      posbefore = pos;
      pos = random.nextInt(backgroundImages.length);
    });
  });
  }

  @override
  Widget build(BuildContext context) {
    Scaffold(
    body:
    Stack(
      children: [ 
      Container(
        width: MediaQuery.of(context).size.width,
        child: FadeInImage(placeholder: AssetImage('assets/'+backgroundImages[posbefore]), 
          image: AssetImage('assets/'+backgroundImages[pos]),
          fit: BoxFit.fill,
        ),
      ),
      Container()...
我发现了以下方法: 首先使用旋转木马插件

  @override
  Widget build(BuildContext context) {
    Scaffold(
    body:
    Stack(
      children: [
      CarouselSlider(  
        options: CarouselOptions(autoPlay: true,
          height: MediaQuery.of(context).size.height,
          autoPlayInterval: Duration(seconds: 5),
          autoPlayCurve: Curves.linear,
          viewportFraction: 1,
        ),
        items: backgroundImages.map((item) =>
          Container(
            child: Image.asset('assets/'+item, fit: BoxFit.fill, width: MediaQuery.of(context).size.width,),
          )
        ).toList(),
      ),
      Container()...
第二


      AnimatedSwitcher( 
        duration: Duration(milliseconds: 800),
        transitionBuilder: (Widget image, Animation<double> animation) {
        return FadeTransition(opacity: animation, child: image,);
        },
        child: Image.asset('assets/'+backgroundImages[pos], key: ValueKey(pos), fit: BoxFit.fill,),
      ),
      Container(

动画切换器(
持续时间:持续时间(毫秒:800),
transitionBuilder:(小部件图像、动画){
返回FadeTransition(不透明度:动画,子对象:图像,);
},
子项:Image.asset('assets/'+backgroundImages[pos],key:ValueKey(pos),fit:BoxFit.fill,),
),
容器(
我的问题在于keyValue的使用。我需要将转换映射为索引更改