2017-05-18 83 views
1

我是新的扑动发展,我有一个问题: 我创建新的AnimatedCrossFade并添加两个不同的ListView到第一个和第二个孩子,但总是一个孩子ListView可滚动。我怎么能在第一个和第二个孩子做可滚动的ListView?一个ListView不可滚动AnimatedCrossFade

(同样的情况简单的GridView。)

+0

只有一个列表视图滚动,这是你的问题na? –

+0

你可以添加一些代码吗?没有你很难帮助你。 –

回答

0

这看起来像在AnimatedCrossFade的错误。我提交了一份issue

您可以通过不使用AnimatedCrossFade并使用FadeTransition构建自己的动画来解决此问题。源代码如下。点击播放按钮,它就会像这样开头

blue

,并最终像这样:

red

您可以再次点击按钮褪色来回。这两个列表都是可滚动的,它会记住你的滚动位置。

import 'package:flutter/widgets.dart'; 
import 'package:flutter/material.dart'; 

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

class MyApp extends StatefulWidget { 
    createState() => new MyAppState(); 
} 

class MyAppState extends State<MyApp> with TickerProviderStateMixin { 
    AnimationController _controller; 
    Key _key1 = new GlobalKey(); 
    Key _key2 = new GlobalKey(); 

    @override 
    void initState() { 
    _controller = new AnimationController(
     duration: const Duration(milliseconds: 700), 
     vsync: this, 
    ); 
    } 

    Widget _buildList(Key key, Color color, double opacity) { 
    return new Opacity(
     opacity: opacity, 
     child: new Container(
     // Keep the hidden ListView around to maintain its scroll position 
     // but set its height to 0.0 so it can't interfere with touches 
     height: opacity == 0.0 ? 0.0 : null, 
     decoration: new BoxDecoration(color: color), 
     child: new ListView(
      key: new GlobalObjectKey(color), 
      children: new List.generate(
      100, 
      (index) => new Text('Item $index'), 
     ), 
     ), 
    ), 
    ); 
    } 

    @override 
    Widget build(BuildContext context) { 
    return new MaterialApp(
     title: 'Flutter Demo', 
     home: new Scaffold(
     floatingActionButton: new FloatingActionButton(
      child: new Icon(Icons.play_arrow), 
      onPressed:() { 
      if (_controller.status == AnimationStatus.dismissed || 
       _controller.status == AnimationStatus.reverse) { 
       _controller.forward(); 
      } else { 
       _controller.reverse(); 
      } 
      }, 
     ), 
     body: new Center(
      child: new Container(
      width: 100.0, 
      height: 100.0, 
      child: new AnimatedBuilder(
      animation: _controller, 
      builder: (BuildContext context, Widget child) { 
       return new Stack(
       children: [ 
        _buildList(_key1, Colors.red[200], _controller.value), 
        _buildList(_key2, Colors.blue[200], 1.0 - _controller.value), 
       ], 
      ); 
      } 
     ), 
     ), 
     ), 
    ), 
    ); 
    } 
} 
} 
+0

谢谢,这工作:) – ZeroProcess