我是 Dart 新手。假设我有一个final List <Character> _characterList;应该是私有的。CharacterList ({Key key, this._characterList}): super (key: key);但是如果命名参数不能以_开头我该如何使用呢?
我想在单击按钮时播放动画。第一次按下时,小部件旋转 180 度,第二次按下时,又旋转 180 度(即返回到其原始位置)。我怎样才能做到这一点?
模拟手势检测按钮
Expanded(
child: GestureDetector(
onTap: () => setState(() {
if (tapValue == 0) {
tapValue++;
animController.forward();
beginValue = 0.0;
endValue = 0.5;
} else {
tapValue--;
animController.forward();
}
}),
child: Container(
child: Image.asset('assets/images/enableAsset.png'),
),
),
),
Run Code Online (Sandbox Code Playgroud)
我想要旋转的小部件
child: CustomPaint (
painter: SmileyPainter(),
child: RotationTransition(
turns: Tween(begin: beginValue, end: endValue,).animate(animController),
child: CustomPaint (
painter: Smile(),
),
),
)
Run Code Online (Sandbox Code Playgroud)
动画控制器
@override
void initState() {
animController = AnimationController(
duration: const Duration(milliseconds: 400),
vsync: this,
);
super.initState();
}
Run Code Online (Sandbox Code Playgroud)