android - Flutter Inkwell导航器上下文在Card中不起作用

标签 android flutter dart

我尝试使用Inkwell制作可触摸的Card,但是我的导航器上下文无法正常工作。
这是我的Card窗口小部件代码,我不明白为什么它不起作用。感谢帮助。

  Widget buildResultCard(data) {
  return Card(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
      elevation: 5,
      child: InkWell(
       //this context have issue 
        onTap: () {Navigator.of(context).pushNamed('yol');},
        child: Container(
            child: Center(
                child: Column(
                  children: [
                    SizedBox(height: 20,),


                    Padding(
                      padding: EdgeInsets.fromLTRB(5, 1, 5, 10),
                      child: Text(data['isim'],
                        style:  GoogleFonts.montserrat(color: Colors.blueGrey[700], fontSize: 24 , textStyle: TextStyle(fontWeight: FontWeight.w400)),
                        textAlign: TextAlign.center,
                      ),
                    ),
                    Divider(thickness: 3,),
                    SizedBox(height: 10,),
                    Padding(
                      padding: EdgeInsets.fromLTRB(5, 1, 5, 10),
                      child: Text(data['tarih'],
                        style:  GoogleFonts.montserrat(color: Colors.blueGrey[700], fontSize: 24 , textStyle: TextStyle(fontWeight: FontWeight.w400)),
                        textAlign: TextAlign.center,
                      ),
                    ),
                    SizedBox(height: 10,),
                   
                  ],
                )
            )
        ),
      )
  );
}
这是我使用的 body 密码。
body: Container(
          height: double.infinity,
          color: myColor,

          child: ListView(
              scrollDirection: Axis.vertical,


                children: <Widget>[

                  SizedBox(height: 10.0),
                  GridView.count(
                      padding: EdgeInsets.only(left: 20.0, right: 20.0),
                      crossAxisCount: 1,
                      childAspectRatio: 0.8,

                      primary: false,
                      shrinkWrap: true,
                      children: tempSearchStore.map((element) {
                        return buildResultCard(element);
                      }).toList()),

                  SizedBox(height: 30,),


                ]),

        )
'yol':(上下文)=> Wrapper()这是我main.dart文件中的路由

最佳答案

您需要在函数参数中添加BuildContextWidget buildResultCard(BuildContext context, data) {或将您的银行卡包装在Builder小部件中。

关于android - Flutter Inkwell导航器上下文在Card中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64043726/

相关文章:

android - Android Studio 创建的 App 可以提交到 Google Play Store 吗?

android - 如何检测 Android 在我的应用程序中选择了哪个布局?

flutter - 在 Flutter 中,定位的 Widget 怎么能感觉到在其父 Stack 区域之外的点击?

dart - 如何在 Flutter 中进行公钥固定?

flutter - Flutter:将Base64字符串图像url转换为File并在FileImage或相关小部件中使用

android - 如何在ubuntu 12.04中设置Android SDK、NDK和JDK路径

java - 启动蓝牙适配器而不弹出

dart - Flutter 在图像上绘制并缩放并移动两者

flutter - 未处理的异常 : A class was used after being disposed. - flutter

android - Flutter Blue无法检测到蓝牙打印机(Zebra ez320)