gpt4 book ai didi

android - 如何仅显示listview.builder的选定索引的进度/进度指示器?

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

因此,我创建了代码,以在按下每个视频下方的下载按钮时显示进度指示,以指示下载文件(视频)的进度。

进度指示器可以正常工作,并且可以完美显示进度。

API JSON结构:https://pastebin.com/raw/JPCyaKMn

问题:

enter image description here

点击视频容器下方的下载按钮后,它将显示ListView.builder中所有视频的进度。

我想只显示被点击(选定)的视频容器的进度,我该怎么做?

我的代码:

@override
Widget build(BuildContext context) {
return data != null
? WillPopScope(
onWillPop: () async => false,
child: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SafeArea(
child: Padding(
padding: const EdgeInsets.only(
left: 10, top: 50.0, bottom: 10.0),
child: Text(
"Videos",
style: TextStyle(
color: Colors.white,
fontSize: 32.0,
fontWeight: FontWeight.w700),
),
),
),
Expanded(
child: ListView.builder(
itemCount: data.body.videos.length,
itemBuilder: (context, index) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
InkWell(
onTap: () async {},
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width -
40,
margin: const EdgeInsets.only(
bottom: 0, top: 20),
height: 70,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(5),
topRight: Radius.circular(5),
bottomLeft: Radius.zero,
bottomRight: Radius.zero),
color: Colors.white,
),
),
],
),
),
),
downloading ? Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: LinearProgressIndicator(
value: _progress,
),
) : Container(),
Center(
child: SizedBox(
width: 128,
child: MaterialButton(
minWidth: 40,
child: Center(
child: Text(
"Download",
style: TextStyle(color: Colors.white),
),
),
height: 40,
color: Colors.red,
onPressed: () async {
_getDownload(data
.body.videos[index].backblazeVideoId);
},
),
),
),
],
);
},
),
),
],
),
resizeToAvoidBottomPadding: false,
backgroundColor: thirdcolor,
),
)
: CircularProgressIndicator();
}

我的下载功能:

// Returns a file (mp4) after the API is given credentials & the fileid of the tapped video
_getDownload(String fileid) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String email = prefs.getString('email');
String token = prefs.getString('accesstoken');

final Directory docDir = await getExternalStorageDirectory();

String docPath = docDir.path;
File docFile = File('$docPath/$fileid.mp4');
var dio = Dio();
var response = await dio.post(
"https://api.myvideovault.com/profile/downloadVideo",
data: {
"email": email,
"token": token,
"method": "download",
"fileid": fileid
},
options: Options(contentType: "application/x-www-form-urlencoded"),
onReceiveProgress: (received, total) {
String lol = "${((received / total) * 100).toInt()} %";
double haha = received/total;
print("${received ~/ total} %");

setState(() {
downloading = true;
_progress = haha;
});
});
}

最佳答案

这里的问题是您的downloading变量会告诉您是否正在下载所有视频。如果您将index作为参数传递给_getDownload并保存了名为index的按钮的_getDownload,这将起作用。
然后,您可以将其用作三元运算符条件以显示线性进度指示器。

关于android - 如何仅显示listview.builder的选定索引的进度/进度指示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61451058/

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