Files
blog_app/lib/layout/drawer.dart
2025-11-15 13:03:10 +08:00

80 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
import 'menu.dart';
Widget buildDrawerHeader(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Container(
width: double.infinity,
height: 200,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [colors.primary, colors.inversePrimary],
),
),
child: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ClipOval(
child: Image.asset(
'assets/images/avatar.jpg',
width: 80,
height: 80,
fit: BoxFit.cover,
),
),
SizedBox(height: 16),
Text(
'Cxx0822',
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
],
),
),
);
}
Widget buildDrawerItem({
required BuildContext context,
required PageInfo page,
required VoidCallback onTap,
required bool isSelected,
}) {
final colors = Theme.of(context).colorScheme;
return Container(
margin: EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: isSelected ? colors.primary.withAlpha(50) : Colors.transparent,
borderRadius: BorderRadius.circular(12),
),
child: ListTile(
leading: Icon(
page.icon,
color: isSelected ? colors.primary : Colors.grey[700],
size: 24,
),
title: Text(
page.title,
style: TextStyle(
color: isSelected ? colors.primary : Colors.grey[800],
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
fontSize: 16,
),
),
trailing:
isSelected
? Icon(Icons.arrow_forward_ios, size: 16, color: colors.primary)
: null,
onTap: onTap,
),
);
}