import 'package:flutter/material.dart';标签:String,title,required,accountName,item,5.30,icon From: https://www.cnblogs.com/kongxiangzeng/p/18246579
Widget buildCustomDrawer({
required String accountEmail,
required String accountName,
required String currentAccountPictureAsset,
required String drawerBackgroundAsset,
required List<DrawerItem> drawerItems,
VoidCallback? onLoginPressed, // Callback for login action
}) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
UserAccountsDrawerHeader(
accountEmail: Text(accountEmail),
accountName: GestureDetector(
onTap: accountName == '未登录' ? onLoginPressed : null, // Check if accountName is '未登录'
child: Text(accountName),
),
currentAccountPicture: CircleAvatar(
backgroundImage: AssetImage(currentAccountPictureAsset),
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(drawerBackgroundAsset),
fit: BoxFit.cover,
),
),
),
for (var item in drawerItems) ...[
ListTile(
title: Text(item.title),
trailing: Icon(item.icon),
),
if (item != drawerItems.last) Divider(),
],
],
),
);
}
class DrawerItem {
final String title;
final IconData icon;
DrawerItem({required this.title, required this.icon});
}