Flutter:使用animate_do包时出现ParentDataWidget使用错误
问题解决:使用animate_do的SlideInUp后Widget报错
问题原因
Positioned组件必须直接作为Stack的子元素,它需要依赖Stack的布局上下文来确定自身位置。你把Positioned嵌套在SlideInUp内部,导致Positioned无法获取到Stack的上下文,这就是报错的根源。
修改后的代码
Stack( children: [ Positioned( bottom: 0, right: 0, left: 0, child: SlideInUp( manualTrigger: true, from: -200, controller: (controller) => playersScoreController = controller, child: Container( padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), color: Helpers().colors['text'], child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Text.rich( TextSpan( children: [ const TextSpan( text: 'Score: ', style: TextStyle(color: Colors.white)), TextSpan( text: '3', style: TextStyle(color: playersColors[0])), const TextSpan( text: ' - ', style: TextStyle(color: Colors.white)), TextSpan( text: '5', style: TextStyle(color: playersColors[1])), ], ), ), Row( children: [ const Image( image: AssetImage('assets/images/medal.png'), height: 20, ), Text( ' 5:566', style: TextStyle(color: playersColors[1]), ), ], ), ], ), playAgainButtonWidget(true), ], ), ), ), ), ], );
说明
把SlideInUp放到Positioned内部,让Positioned直接作为Stack的子元素,这样既保留了动画效果,又能让Positioned正常获取Stack的布局上下文完成定位。
内容的提问来源于stack exchange,提问作者Dani
相关产品推荐
相关产品推荐

