【发布时间】:2019-07-15 13:32:30
【问题描述】:
我有两个连续的可扩展按钮占据了所有屏幕宽度。在左键单击时,我希望左键占据整个屏幕宽度,右键从屏幕右侧消失。以下是我目前取得的成就:
正如您所注意到的,当没有足够的空间来渲染它时,右边的按钮会在最后被压扁。我只是希望它继续移出屏幕而不改变它的宽度。我可以通过为按钮设置一行文本来实现这一点,但我希望该解决方案一般适用于所有小部件(看起来右侧有足够的空间来呈现它)。
目前的解决方案:
import 'package:flutter/material.dart';
void main() => runApp(TestAnimation());
class TestAnimation extends StatefulWidget {
@override
_TestAnimationState createState() => _TestAnimationState();
}
class _TestAnimationState extends State<TestAnimation> with SingleTickerProviderStateMixin {
AnimationController _animationController;
Animation _animation;
@override
void initState() {
super.initState();
_animationController = AnimationController(duration: Duration(seconds: 2), vsync: this);
_animation = IntTween(begin: 100, end: 0).animate(_animationController);
_animation.addListener(() => setState(() {}));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Row(
children: <Widget>[
Expanded(
flex: 100,
child: OutlineButton(
child: Text("Left"),
onPressed: () {
if (_animationController.value == 0.0) {
_animationController.forward();
} else {
_animationController.reverse();
}
},
),
),
Expanded(
flex: _animation.value,
// Uses to hide widget when flex is going to 0
child: SizedBox(
width: 0,
child: OutlineButton(
child: Text(
"Right",
),
onPressed: () {},
),
),
)
],
),
),
),
);
}
}
【问题讨论】:
标签: animation dart flutter widget