我有一個snapshotData變數,其中包含在搜索欄中用于查找書籍的欄位作者。然后我有一個小部件 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),
),
),
);
},
);
}
當有人在 GestureDetector 中雙擊一本書時,我想顯示另一個頁面,該頁面應該專門顯示被點擊的書籍中的書籍詳細資訊:
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 所提到的錯誤。所以我將關閉這篇文章并提出另一個問題,關于我如何在點擊一本書時顯示書的詳細資訊
uj5u.com熱心網友回復:
您正在使用 Get.to 進行導航,使用 GetMaterialApp 更改 MaterialApp 小部件。可能它在 main.dart 檔案中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/334718.html
