我无法刷新屏幕



我使用get包,我有一个底部导航,它用Obx更新。还有一个元素搜索,在页面的顶层,所有内容都更新得很好,但当我推送时,当前页面不会更新,只有当你调用热重载时。有人怀疑嵌套页面没有更新,因为它超出了BottomNavigation,并且没有Obx小部件。

我的页面导航控制器:

Widget build(BuildContext context) {
SizeConfig().init(context);
final BottomPageController landingPageController =
Get.put(BottomPageController(), permanent: false);
return SafeArea(
child: Scaffold(
bottomNavigationBar:
BottomNavigationMenu(landingPageController: landingPageController),
body: Obx(
() => IndexedStack(
index: landingPageController.tabIndex.value,
children: [
ProductPage(),
MapPage(),
ClientPage(),
NotePage(),
],
),
),
),
);
}

需要更新ListView的我的页面,具体取决于搜索栏中输入的值:

class Product extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetX<ProductController>(
init: ProductController(),
builder: (controller) {
return FutureBuilder<List<ProductsCombined>>(
future: controller.filterProduct.value,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Expanded(
child: Container(
child: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) =>
ProductCards(
product: snapshot.data[index],
),
),
),
);
} else {
return Center(child: CircularProgressIndicator());
}
},
);
},
);
}
}

Product类中还有一个嵌套页面,可以通过以下方式访问:

onTap: () => {
Get.toNamed(StoresScreen.routeName, arguments: companies)}

Product类会立即更新,不需要单击"热重载"即可执行此操作,并且转换到的ProductScreen类也无法再更新,这两个类完全相同。搜索栏可以工作,但只有在热重新加载后才能过滤掉元素。

如果你需要我代码的其他部分,比如处理ListViewcontroller,请写下来,我会附上它。

编辑:我添加了一个视频链接,屏幕未更新

Obx使用起来有点棘手。我总是建议使用GetX

试试这个:

Obx(
() => IndexedStack(
index: Get.find<BottomPageController>().tabIndex.value,
children: [
...
],
),
),

如果它不起作用,也可以在这种情况下使用GetX<BottomPageController>。它适用于所有条件

最新更新