Flutter腹板嵌套布线

x6492ojm  于 2023-05-23  发布在  Flutter
关注(0)|答案(1)|浏览(153)

嘿,我正试图设置在Flutter网络,与一个抽屉的左侧与2个菜单和右侧其各自的网页,抽屉。总是在左侧打开,当我点击每个按钮时,只有右侧应该建立,我通过做条件检查实现了这一点,但它不是正确的方式,因为如果我复制URL并粘贴到某个地方重新加载,所以我想设置正确的路由,我尝试使用Go路由器,但我得到的只是新页面,有人建议我执行的方法

const DashBoard({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Row(
        children: const [
          Expanded(flex: 1, child: EnquiryDrawer()),
          Expanded(flex: 6, child: EnquiryListScreen())
        ],
      ),
    );
  }
}

我已经分享了图像,基本上我想要的是只有右侧小部件应该建立,左侧应该是固定的,

kognpnkq

kognpnkq1#

您可以通过将基页设置为堆栈来实现这一点:

class PageWrapper extends StatelessWidget {
  const PageWrapper(this.child, {Key? key}) : super(key: key);
  
  final Widget child;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Stack(
          children: [
            child,
            //const MenuDrawer(),
          ],
        ),
    );
  }
}

那么在goRouter中,你可以使用这个作为ShellRoute:

GoRouter(
   routes: [
    ShellRoute(
        builder: (context, state, child) => PageWrapper(child),
        routes:[
         //your routes here
        ]
    ],
);

这将在PageWrapper类中构建shellroute的所有子路由

相关问题