我正在尝试将 PageView 嵌套在 PageView 中并访问第二个 PageView 的控制器。
父级的结构如下所示:
Scaffold(
appBar: buildAppBar(context),
body: PageView(
children: [
Column( //this column represents the first view of this pageview
children: [
Expanded(
flex: 3,
child: buildPreviewWidget(selection, _buildCropPreview),
),
Expanded(
flex: 2,
child: MediaGrid(
allowMultiSelection: multiSelectable,
collection: allCollection),
),
],
),
CameraScreen() //this is the second view of the pageview and it also has a pageview with 2 children, i want to access its pageController
],
),
bottomNavigationBar: buildBottomNavigationBar(),
);
这是底部导航栏:
BottomNavigationBar buildBottomNavigationBar() {
return BottomNavigationBar(
currentIndex: pageIndex,
items: [
const BottomNavigationBarItem(
label: "Gallery",
icon: SizedBox.shrink(),
),
const BottomNavigationBarItem(
label: "Photo",
icon: SizedBox.shrink(),
),
const BottomNavigationBarItem(
label: "Video",
icon: SizedBox.shrink(),
),
],
onTap: (index) {
//if index == 0, go to this pageViews first page
//if index == 1, go to this pageviews second page (CameraScreen) and to its first page
//if index == 2, go to this pageviews second page (CameraScreen) and to its second page
},
);
}
如您所见,父母 pageView 只有 2 个孩子,但底部导航栏有 3 个项目。
我已经将我想要的功能编写为伪onTap()
代码bottomNavigationBar
我试过的
我试图使CameraScreen
s pageControllers 索引成为必需的属性,以便我可以使用所需的索引重建它,但这不起作用。
我也尝试实现通知,但这也不起作用。可能是因为接收器必须处于活动状态?
是否有捷径可寻?