有人能帮我调试这个食谱应用程序的手势检测器在扑动?



我有一些代码的食谱应用程序在扑动,我决定创建一个食谱详细页面,并将其纳入应用程序。我做了这个页面,并添加了一个手势探测器以及导航.push()到旋转木马和流行的食谱列表,但代码似乎是错误的,因为图像旋转木马不显示。流行的食谱列表也不会指向详细页面。这里是存储库https://github.com/sldgjrg/Recipe-App-Flutter

缺少一些东西,需要优化如下:

home_screen.dart构建函数需要修改如下:

Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: const Color(0xFFe7eefb),
body: Column(
children: [
Expanded(
child: PageViewRecipeList(
recipes: recipes,
onRecipeTap: (recipe) {
Navigator.pushNamed(
context,
RecipeDetailArguments.routeName, // use the named route
arguments: recipe,
);
},
),
),
const Expanded(child: PopularRecipeList()),
],
),
bottomNavigationBar: const MyBottomNavigationBar(),
floatingActionButton: FloatingActionButton(
onPressed: () {
showSearch(context: context, delegate: MySearchDelegate());
},
backgroundColor: Colors.orange,
child: const Icon(Icons.search),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
),
);
}

main.dart缺少onGenerateRoute。这是必需的生成到想要打开的页面的动态路由

home: const OnboardingScreen(),
onGenerateRoute: (settings) {
if (settings.name == '/recipe_detail') {
final value = settings.arguments as Recipe; // Retrieve the value.
return MaterialPageRoute(
builder: (_) => RecipeDetailPage(
recipe: value)); // Pass it to RecipeDetailPage.
}
return null; // Let `onUnknownRoute` handle this behavior.
},

popular_recipe_list.dart中,导入RecipeDetailArguments类并更新onTap函数如下:

onTap: () {
Navigator.pushNamed(
context,
RecipeDetailArguments.routeName, // use the named route
arguments: recipes[index],
);
// Navigator.pushNamed(
//   context,
//   '/recipe-detail',
//   arguments: recipes[index],
// );
},