[英]Flutter - Page replacement system with GetX not working
I have a code like this:我有这样的代码:
main.dart
: main.dart
:
body: GetX<PaginationController>(
init: PaginationController(),
initState: (_) {},
builder: (controller) {
if (controller.PageIndex.value == 0) {
return Pages[0];
} else if (controller.PageIndex.value == 1) {
return Pages[1];
} else if (controller.PageIndex.value == 2) {
return Pages[2];
}
},
),
PaginationController
: PaginationController
:
class PaginationController extends GetxController {
RxInt PageIndex = RxInt(0);
}
Coming to the question, when I press the button, I want it to switch from one of the pages in the menu to another.谈到这个问题,当我按下按钮时,我希望它从菜单中的一个页面切换到另一个页面。 But it doesn't switch.
但它不会切换。 In Controller the value of
PageIndex
changes but the page does not.在 Controller 中,
PageIndex
的值会发生变化,但页面不会。
Menu codes:菜单代码:
PaginationController paginationController = PaginationController();
int PageIndex = paginationController.PageIndex.value;
//...
bottomNavigationBar: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(30),
topLeft: Radius.circular(30),
),
boxShadow: [
BoxShadow(color: Colors.black38, spreadRadius: 0, blurRadius: 10),
],
),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
),
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Color.fromARGB(255, 53, 53, 57),
selectedFontSize: 16,
unselectedFontSize: 13,
selectedItemColor: Color(0xFFFBBF24),
selectedLabelStyle: TextStyle(color: Color(0xFFFBBF24), fontFamily: "Inter Bold"),
unselectedIconTheme: IconThemeData(
color: Color.fromARGB(255, 192, 192, 192),
),
unselectedLabelStyle: TextStyle(fontFamily: "Inter Regular"),
unselectedItemColor: Color.fromARGB(255, 192, 192, 192),
currentIndex: PageIndex,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
label: "Ana Sayfa",
icon: Icon(Icons.home)
),
BottomNavigationBarItem(
label: "Sepet",
icon: Icon(Icons.shopping_basket_outlined)
),
BottomNavigationBarItem(
label: "Cüzdan",
icon: Icon(Icons.account_balance_wallet_rounded)
),
],
onTap: (int index) {
setState(() {
PageIndex = index;
print(PageIndex);
print(index);
});
},
),
),
),
To change the page, I wrote the following code:为了更改页面,我编写了以下代码:
onPressed: () {
setState(() {
PageIndex = 2;
});
},
Menu and Body codes in one file.菜单和正文代码在一个文件中。
The value in PaginationController
changes but the page does not. PaginationController
中的值会发生变化,但页面不会。 Why could it be?为什么会这样? How can I solve the problem?
我该如何解决这个问题? Thanks in advance for your help.
在此先感谢您的帮助。
try to look at this it might help you the one i answered back试着看看这个它可能会帮助你我回答的那个
Flutter: How to control a PageView by GetxController? Flutter:如何通过 GetxController 控制 PageView?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.