flutter - 如何在 Flutter 中使用 ListTile 导航到新页面/路由?
问题描述
在 Flutter 中,当我按下 ListTile 小部件时,我试图导航到新页面。我正在尝试使用 ontap() 函数,但是它似乎不起作用。
ListTile(
leading: Icon(Icons.border_color),
title: Text('Freelance English Native needed'),
subtitle: Text('Requirements: Native English'),
onTap: () {
Navigator.pushNamed(context, '/second');
},
),
MaterialApp(
// Start the app with the "/" named route. In this case, the app starts
// on the FirstScreen widget.
initialRoute: '/',
routes: {
// When navigating to the "/" route, build the FirstScreen widget.
'/': (context) => MyApp(),
// When navigating to the "/second" route, build the SecondScreen widget.
'/second': (context) => SecondScreen(),
},
);
解决方案
尝试这个
ListTile(
leading: Icon(Icons.border_color),
title: Text('Freelance English Native needed'),
subtitle: Text('Requirements: Native English'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
},
),
推荐阅读
- r - 在 r 中按组标记非连续值
- javascript - 如何根据 div 大小显示画布
- redux - Redux RTK 查询:getDefaultMiddleware 不是函数
- javascript - UseQuery 在通过 apollo react 使用 useMutations 重定向后不起作用
- c - 将 meta-iot-cloud 添加到 bitbake 时,rootfs 中不存在 azure-macro-utils
- javascript - 在移动设备中查看时如何仅显示一定数量的页面?
- google-apps-script - 将查找特定值并在满足条件时将其替换为另一个工作表中的公式的 Google Apps 脚本
- python - 在 python 中处理大型列表的最有效方法
- swift - SwiftUI:如何让手机振动?
- c++ - 未初始化的 C++ 指针的默认行为是什么