屏幕和它下面有控制器当我导航第一次页面加载,但当我导航第二次它不像第一次重新加载我面临这个问题,因为要从API请求数据每次我打开页面控制器是下面的屏幕代码苏任何想法
Widget build(BuildContext context) {
Get.put(MainpageConrolloerImp());
return GetBuilder<MainpageConrolloerImp>(
builder: (controller) => Scaffold(
drawer: NavigationDrawer(
name: thecontrol.thename,
),
body: controller.pageslist.elementAt(controller.currentpage),
bottomNavigationBar: Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16)),
color: Colors.white,
boxShadow: [
BoxShadow(
blurRadius: 20,
color: Colors.black.withOpacity(.1),
)
],
),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4.0, vertical: 16),
child: GNav(
tabBorderRadius: 24,
rippleColor: Colors.grey[300]!,
hoverColor: Colors.grey[100]!,
gap: 4,
activeColor: const Color.fromRGBO(227, 29, 26, 1),
iconSize: 24,
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 12),
duration: const Duration(milliseconds: 500),
tabBackgroundColor:
const Color.fromRGBO(227, 29, 26, 0.15),
color: Colors.grey,
tabs: [
GButton(
onPressed: () {
controller.navigationPage(0);
},
icon: Icons.home,
text: '',
),
],
),
),
))));
}
////////////////////////
abstract class MainpageConrolloer extends GetxController {
navigationPage(int currentpage);
}
class MainpageConrolloerImp extends MainpageConrolloer {
int currentpage = 0;
List<Widget> pageslist = [
const HomePage(),
const cartPage(),
const CategoryPage(),
const FavoritePage(),
const MaintainPage(),
];
@override
navigationPage(int i) {
currentpage = i;
update();
}
}
1条答案
按热度按时间tzcvj98z1#
你可以让你的主页和其他页面变成StatefulWidget。提供initState方法-〉每次在页面之间导航时,它都会再次调用initState
如果你坚持使用无状态-〉请提供Gnav包的onTabChanged函数