Obx-重建变量更改列表



我正在尝试制作一个故事进度条
我有一个PageView,它每页显示一个新视频,顶部有一个进度条,当我滚动到它时,它应该显示每个PageView的进度。
问题是故事栏只更新第一个进度条。我需要他们继续收听最新消息。

视频进度码:

RxDouble getVideoProgress(int storyBarIndex) {
if (storyBarIndex < pageIndex.value) {
return 1.0.obs;
} else if (storyBarIndex == pageIndex.value) {
final properVideoController = Get.put(
ProperVideoController(video: pageVideo!.value),
tag: ValueKey(pageVideo!.value.uid + '_' + user.authUid + 'tt')
.toString());
return properVideoController.videoProgress;
} else {
return 0.0.obs;
}

}

ListView代码:

Widget build(BuildContext context) {
return GetBuilder<ProfileViewController>(
init: ProfileViewController(),
builder: (controller) => Container(
width: Get.width,
child: LayoutBuilder(
builder: ((context, constraints) => Column(
children: [
Container(
height: 4,
child: ListView.builder(
itemCount: itemCount,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return _ProgressBarStep(
width: constraints.maxWidth / 6.2,
index: index,
);
}),
),
],
))),
),
);

}

单层栏小部件

Widget build(BuildContext context) {
return GetBuilder<ProfileViewController>(
init: ProfileViewController(),
builder: (controller) {
return Padding(
padding: const EdgeInsets.only(right: 0.0),
child: Obx(
() {

return LinearPercentIndicator(
barRadius: Radius.circular(20),
animation: true,
width: width,
lineHeight: 9.0,
percent: controller.getVideoProgress(index).value,
// ignore: deprecated_member_use
linearStrokeCap: LinearStrokeCap.roundAll,
backgroundColor: TabooColors.darkBlueGrey,
progressColor: TabooColors.red,
);
},
));
});

}

您可以删除GetBuilder小部件,只需使用Obx即可。需要添加Get.put(ProfileViewController(((;在Widget build((方法之上。我希望这能对你有所帮助。请浏览文档:https://pub.dev/packages/get

当我们使用GetBuilder时,我们还需要调用GetxController类中的update((方法来更新UI

最新更新