我已经根据现有问题的现有解决方案解决了上一个问题。
以下是Github指向项目的链接:https://github.com/Aaklii/flutter_app
drawer: buildDrawer(context),
class ListDrawer extends StatefulWidget {
List<ListClass> listOjects;
ListDrawer({this.listOjects});
@override
_ListDrawerState createState() => _ListDrawerState();
}
class _ListDrawerState extends State<ListDrawer> {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: EdgeInsets.all(20),
child: ListView.builder(
itemCount: widget.listOjects.length,
itemBuilder: (context, index) {
return CustomListTile(
listObject: widget.listOjects[index],
// isSelected:
// selectedIndex != null && selectedIndex == index
// ? true
// : false,
index: index,
);
},
),
),
)
],
),
);
}
}
Drawer buildDrawer(BuildContext context) {
return Drawer(
child: SafeArea(
child: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: EdgeInsets.all(20),
child: ListView.builder(
itemCount: listOjects.length,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
setState(() {
onSelected(index);
});
Navigator.of(context).pop();
},
child: CustomListTile(
listObject: listOjects[index],
isSelected:
selectedIndex != null && selectedIndex == index
? true
: false,
index: index,
),
);
},
),
),
)
],
),
),
);
}