gpt4 book ai didi

flutter - 如何在按钮小部件中显示进度指示器(如图所示)

转载 作者:行者123 更新时间:2023-12-03 03:34:30 24 4
gpt4 key购买 nike

我是新手。我已经实现了一个按钮,并且我想在单击按钮时像下面一样显示进度指示器。

enter image description here

我已经使用percent indicator包实现了,但是没有正确归档。

我的代码是

class DownloadIndicatorWidget extends StatefulWidget {
bool download = false;

@override
_DownloadIndicatorWidgetState createState() => _DownloadIndicatorWidgetState();
}

class _DownloadIndicatorWidgetState extends State<DownloadIndicatorWidget> {

@override
Widget build(BuildContext context) {
return widget.download?ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
height: 40,
decoration: BoxDecoration(
border: Border.all(
color: Color(0xff9F00C5), // <--- border color
width: 10.0,
),
borderRadius: BorderRadius.circular(10.0)
),
child: LinearPercentIndicator(
// width: MediaQuery.of(context).size.width -
// width:107,
animation: true,
lineHeight: 40.0,
animationDuration: 2500,
percent: 1,
center: Text(
"Downloading...",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w800,
fontSize: 14
)),
linearStrokeCap: LinearStrokeCap.roundAll,
progressColor: Color(0xff9F00C5),
backgroundColor: Colors.white,
),
),
):RaisedButton(
onPressed: () {
setState(() {
widget.download = true;
});
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
padding: EdgeInsets.all(0.0),
child: Ink(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Color(0xff9F00C5), Color(0xff9405BD),Color(0xff7913A7),Color(0xff651E96), Color(0xff522887)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
borderRadius: BorderRadius.circular(10.0)
),
child: Container(
constraints: BoxConstraints(maxWidth: 300.0, minHeight: 50.0),
alignment: Alignment.center,
child: Text(
"Download",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w800,
fontSize: 18
),
),
),
),
);
}
}


那么,如何正确实现对图像的归档呢?如果还有其他方法可以实现,请向我建议我确实需要此方法。
提前致谢!

最佳答案

此代码可以为您提供帮助。

import 'dart:async';

import 'package:flutter/material.dart';

class Progress extends StatefulWidget {
@override
_ProgressState createState() => _ProgressState();
}

class _ProgressState extends State<Progress> {
double progress = 0;

void initState() {
super.initState();

Timer.periodic(Duration(milliseconds: 100), (Timer t) {
setState(() {
if (progress > 120) {
progress = 0;
} else {
progress += 5;
}
});
});
}

@override
Widget build(BuildContext context) {
return Center(
child: FlatButton(
onPressed: () {},
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
height: 45,
width: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Colors.indigo,
width: 1,
)),
child: Stack(
children: <Widget>[
AnimatedContainer(
color: Colors.indigo,
width: progress,
duration: Duration(milliseconds: 100),
curve: Curves.fastOutSlowIn,
),
Center(child: Text("Downloading...")),
],
))),
),
);
}
}

关于flutter - 如何在按钮小部件中显示进度指示器(如图所示),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61874606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com