Issue
I have some icons in a drawer, but none of them seem to navigate to another page, and I have no clue why. There are no errors, etc. it's just a navigation drawer, with a few buttons, and MainDrawer.dart contains the Drawer, while DrawerListTile.dart contains the attributes of each tile on the drawer.
Here is the MainDrawer.dart
import 'package:iona_central/Screens/News/news.dart';
import 'package:iona_central/Screens/Exam/Exam_Rseult.dart';
import 'package:iona_central/Screens/Leave_Apply/Leave_apply.dart';
import 'package:iona_central/Screens/home.dart';
import 'package:iona_central/Widgets/DrawerListTile.dart';
class MainDrawer extends StatefulWidget {
@override
_MainDrawerState createState() => _MainDrawerState();
}
class _MainDrawerState extends State<MainDrawer> {
@override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
children: [
DrawerListTile(
imgpath: "home.png",
name: "Home",
ontap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => Home(),
),
);
}),
DrawerListTile(
imgpath: "news.png",
name: "News",
ontap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => attendance(),
),
);
},
),
//DrawerListTile(imgpath: "profile.png", name: "Profile", ontap: () {}),
DrawerListTile(
imgpath: "ipsports.png",
name: "Sports",
ontap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => ExamResult(),
),
);
},
),
/*DrawerListTile(
imgpath: "calendar.png", name: "Time Table", ontap: () {}), */
DrawerListTile(
imgpath: "gfl.png",
name: "GFL",
ontap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => LeaveApply(),
),
);
},
),
DrawerListTile(
imgpath: "club.png",
name: "Clubs",
ontap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => LeaveApply(),
),
);
},
),
],
));
}
}
Here is DrawerListTile.dart
import 'package:flutter/material.dart';
class DrawerListTile extends StatelessWidget {
final String name;
final String imgpath;
final Function ontap;
const DrawerListTile(
{Key? key,
required this.name,
required this.imgpath,
required this.ontap})
: super(key: key);
@override
Widget build(BuildContext context) {
return ListTile(
onTap: () => ontap,
leading: Image.asset(
"assets/${imgpath}",
height: 30,
),
contentPadding: EdgeInsets.only(
left: 70,
top: 5,
bottom: 5,
),
title: Text(
"${name}",
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
);
}
}
Solution
Change th line
onTap: () => ontap,
to
onTap: ontap,
or
onTap: () => ontap.call(),
Answered By - Tanvir Ahmed Khan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.