我有一个 CircularProgressIndicator,用于在用户按下按钮时显示进度。但是,当我打开使用此类的屏幕时,它会显示加载动画,我不知道为什么。当屏幕打开时,它不应该在用户按下按钮之前显示动画。
当屏幕打开时,您会在此页面上看到类似于动画的内容:https ://www.c-sharpcorner.com/article/create-chrome-like-loading-animation/
class _MsgInputState extends State<MsgInput> with TickerProviderStateMixin {
AnimationController? controller;
@override
void initState() {
super.initState();
initialize();
}
@override
void dispose() {
controller?.dispose();
super.dispose();
}
void initialize() async {
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 3),
)..addListener(() {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Align(
alignment: Alignment.bottomLeft,
child: Column(
children: [
Row(
children: [
GestureDetector(
onTap: () async {
controller?.forward();
},
onLongPressDown: (details) async {
controller?.forward();
},
onLongPressUp: () async {
controller?.stop();
controller?.reset();
},
child: Text('Record'),
),
],
),
Row(
children: <Widget>[
SizedBox(width: 100),
CircularProgressIndicator(
value: controller?.value,
semanticsLabel: 'Linear progress indicator',
),
],
),
],
),
)
);
}