【发布时间】:2021-12-07 22:44:57
【问题描述】:
有这样一个类
class ProgressBar extends StatefulWidget {
final double size;
final String text;
final String textSize;
ProgressBar({Key? key, required this.size, required this.text, required this.textSize}) : super(key: key);
@override
_ProgressBarState createState() => _ProgressBarState();
}
class _ProgressBarState extends State<ProgressBar> with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> animation;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(
seconds: 5,
),
);
animation = Tween<double>(
begin: 0,
end: widget.size,
).animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOut))
..addListener(() {
setState(() {});
});
_controller.forward();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
return Padding(
padding: const EdgeInsets.only(left: 20, right: 20, top: 12, bottom: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.text, style: theme.textTheme.bodyText1!.copyWith(fontSize: 14, color: theme.colorScheme.primary)),
Padding(
padding: const EdgeInsets.only(top: 15, bottom: 6),
child: LinearProgressIndicator(
value: _controller.value,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('${animation.value.toStringAsFixed(2)} Мб из ${widget.textSize} Мб', style: theme.textTheme.bodyText2!.copyWith(color: Color(0xff8F92A1), fontSize: 12)),
Text('Загрузка...', style: theme.textTheme.bodyText2!.copyWith(color: Color(0xff8F92A1), fontSize: 12)),
],)
],
),
);
}
}
我需要在另一个类中使用“动画”。
child: ListView.separated(
padding: EdgeInsets.zero,
shrinkWrap: true,
scrollDirection: Axis.vertical,
physics: NeverScrollableScrollPhysics(),
separatorBuilder: (BuildContext context, int index) => Divider(color: Color(0xffF3F6F8)),
itemCount: items.length + 1,
itemBuilder: (context, index) {
if (index == 0) {
return _rowAdd();
}
return animation.isCompleted ? ProgressBar(size: items[index - 1].sizeFile, text: items[index - 1].nameFile, textSize: items[index - 1].sizeFile.toStringAsFixed(2),) :
Padding(
...
);
如何正确操作?这是一个临时的拐杖。一般来说,我的 file_picker 将数据添加到 Item 类,我需要一个空的 CallBack 来为每个文件提供一个空的回调,并暂时在其中设置动画超时,但我还不知道该怎么做......
【问题讨论】:
标签: flutter dart navigation var