如何在单击图书时显示图书详细信息



我有一个snapshotData变量,其中包含在搜索栏中用于查找图书的字段author。然后,我有一个小部件searchedData,它根据作者显示图书列表:

Widget searchedData() {
return ListView.builder(
itemCount: snapshotData.docs.length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onDoubleTap: () {
Get.to(showBookDetails(),
transition: Transition.downToUp,
arguments: snapshotData.docs[index]);
},
child: ListTile(
leading: const Icon(Icons.account_circle),
title: Text(
snapshotData.docs[index]['Title'],
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 24.0),
),
subtitle: Text(
snapshotData.docs[index]['Author'],
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.normal,
fontSize: 24.0),
),
),
);
},
);
}

当有人在手势检测器中双击一本书时,我想显示另一个页面,该页面应该显示从点击的书中特定的书籍细节:

Widget showBookDetails() {
return Scaffold(

}

但是当我双击一本书时,我得到错误:

You are trying to use contextless navigation without
a GetMaterialApp or Get.key.
If you are testing your app, you can use:
[Get.testMode = true], or if you are running your app on
a physical device or emulator, you must exchange your [MaterialApp]
for a [GetMaterialApp].

我如何确保当我在searchedData中点击图书时,我可以在小部件showBookDetails中显示图书详细信息?

编辑

所以我通过在main.dart中使用GetMaterialApp更改MaterialApp解决了提到的错误。所以我将结束这篇文章作为解决和问另一个问题,我如何才能显示图书的详细信息时,点击一本书

您正在使用Get。要进行导航,使用GetMaterialApp更改MaterialApp小部件。可能是main。飞镖文件。

相关内容