有没有其他方法可以导航到其他页面,使页面看起来像 gridview in flutter?

Is there any alternative to navigate to other pages making page look like gridview in flutter?

我正在构建一个服务应用程序,其中的功能将在 flutter 中显示为 gridview,当 tappeed/pressed 在网格上的特定图块上时,它应该导航到另一个 android 页面。有什么办法可以使用颤动来做到这一点吗? 我尝试使用 gridview,但无法访问网格上的独立图块。当我尝试使用容器并尝试使用按钮时,将会出现像素溢出。有什么办法可以解决这个问题吗?

      body: CustomScrollView(
  primary: false,
  slivers: <Widget>[
    SliverPadding(
      padding: const EdgeInsets.all(20),
      sliver: SliverGrid.count(
        crossAxisSpacing: 10,
        mainAxisSpacing: 10,
        crossAxisCount: 2,
        children: <Widget>[
          Container(
            padding: const EdgeInsets.all(8),
            child: Image.asset('assets/images/lungs.jpg'),
          ),
          Container(
            padding: const EdgeInsets.all(8),
            child: Image.asset('assets/images/cancer.jpg'),
          ),
        ],
      ),
    ),
  ],
)

这是我尝试使用的另一种方法

您可以在每次点击 InkWell 时访问索引,请参阅下面的代码,这里生成了一个包含 100 个项目的列表,并且每个索引都打印在 onTap: (){print('$index');},

    SliverPadding(
      padding: const EdgeInsets.all(20),
      sliver: SliverGrid.count(
  // Create a grid with 2 columns. If you change the scrollDirection to
  // horizontal, this produces 2 rows.
         crossAxisSpacing: 10,
        mainAxisSpacing: 10,
        crossAxisCount: 2,
  // Generate 100 widgets that display their index in the List.
  children: List.generate(100, (index) {
    return Center(
      child: InkWell(
        onTap: (){
  print('$index');
     // use this line if you want to pass index position on the next page
             Navigator.of(context).pushNamed(
          'YOUR_PAGE', arguments: '$index');
     //or if you don't want to pass anything use this
             Navigator.of(context).pushNamed(
          'YOUR_PAGE');
       },
      child:Text(
        'Item $index',
        style: Theme.of(context).textTheme.headline,
      )
      ),
    );
  }),
),
    ),

如何在下一页获取传递的参数?

  @override
  Widget build(BuildContext context) {
    // Extract the arguments from the current ModalRoute settings 
    final var args = ModalRoute.of(context).settings.arguments;

了解更多Pass arguments to a named route Read this

输出