我在Flutter中使用Expansiontile,它可以正常工作,但我想在点击时提供点击操作以路由到新页面,但是如下图所示,我无法使用它,我使用了ontap,但它给了我error。可与listTile一起使用,在这里我可以单击子要约将我路由到page1,有没有办法做到这一点?
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('project1',
textAlign: TextAlign.center,
style:
TextStyle(fontSize: 25, fontFamily: 'VampiroOne', color: Colors.grey)),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/drawer-back.png"),
fit: BoxFit.cover)),
),
ListTile(
leading: Icon(Icons.home),
title: Text('Home'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyHomePage(),
),
);
},
),
ExpansionTile(
title: Text(
"Offers",
),
leading: CircleAvatar(
backgroundImage: AssetImage("assets/images/bin.png"),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyHomePage(),
),
);
},
children: <Widget>[
ListTile(
title: Text(
'sub offers',
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => page1(),
),
);
}),
]),
],
),
)
答案 0 :(得分:1)
ExpantionTile
具有onExpansionChanged
,它告诉您何时轻按窗口小部件。
以下是使用onExpansionChanged
的代码:
Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('project1',
textAlign: TextAlign.center,
style:
TextStyle(fontSize: 25, fontFamily: 'VampiroOne', color: Colors.grey)),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/drawer-back.png"),
fit: BoxFit.cover)),
),
ListTile(
leading: Icon(Icons.home),
title: Text('Home'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyHomePage(),
),
);
},
),
ExpansionTile(
onExpansionChanged: (bool isExpanded) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyHomePage(),
),
);
},
title: Text(
"Offers",
),
leading: CircleAvatar(
backgroundImage: AssetImage("assets/images/bin.png"),
),
children: <Widget>[
ListTile(
title: Text(
'sub offers',
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => page1(),
),
);
},
),
],
),
],
),
)