在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(),
},
);
答案 0 :(得分:0)
尝试
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()),
);
},
),