109 lines
2.8 KiB
Dart
109 lines
2.8 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:google_fonts/google_fonts.dart';
|
||
|
|
import 'package:provider/provider.dart';
|
||
|
|
import 'package:shadcn_ui/shadcn_ui.dart';
|
||
|
|
import '../../../providers/auth_provider.dart';
|
||
|
|
|
||
|
|
/// 首页顶栏 - Logo + 搜索/通知/头像
|
||
|
|
class HeaderBar extends StatelessWidget {
|
||
|
|
const HeaderBar({super.key});
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
final colorScheme = Theme.of(context).colorScheme;
|
||
|
|
|
||
|
|
return Padding(
|
||
|
|
padding: const EdgeInsets.symmetric(
|
||
|
|
horizontal: 16,
|
||
|
|
vertical: 8,
|
||
|
|
),
|
||
|
|
child: Row(
|
||
|
|
children: [
|
||
|
|
// Logo
|
||
|
|
Text(
|
||
|
|
'MONISUO',
|
||
|
|
style: GoogleFonts.inter(
|
||
|
|
fontSize: 18,
|
||
|
|
fontWeight: FontWeight.w700,
|
||
|
|
letterSpacing: 1,
|
||
|
|
color: colorScheme.onSurface,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
const Spacer(),
|
||
|
|
// Search button
|
||
|
|
_IconButton(
|
||
|
|
icon: LucideIcons.search,
|
||
|
|
colorScheme: colorScheme,
|
||
|
|
onTap: () {},
|
||
|
|
),
|
||
|
|
const SizedBox(width: 8),
|
||
|
|
// Bell button
|
||
|
|
_IconButton(
|
||
|
|
icon: LucideIcons.bell,
|
||
|
|
colorScheme: colorScheme,
|
||
|
|
onTap: () {},
|
||
|
|
),
|
||
|
|
const SizedBox(width: 8),
|
||
|
|
// Avatar
|
||
|
|
Consumer<AuthProvider>(
|
||
|
|
builder: (context, auth, _) {
|
||
|
|
final username = auth.user?.username ?? '';
|
||
|
|
final initial = username.isNotEmpty ? username[0].toUpperCase() : '?';
|
||
|
|
return Container(
|
||
|
|
width: 32,
|
||
|
|
height: 32,
|
||
|
|
decoration: BoxDecoration(
|
||
|
|
color: colorScheme.primary,
|
||
|
|
shape: BoxShape.circle,
|
||
|
|
),
|
||
|
|
alignment: Alignment.center,
|
||
|
|
child: Text(
|
||
|
|
initial,
|
||
|
|
style: GoogleFonts.inter(
|
||
|
|
fontSize: 14,
|
||
|
|
fontWeight: FontWeight.w600,
|
||
|
|
color: Colors.white,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class _IconButton extends StatelessWidget {
|
||
|
|
const _IconButton({
|
||
|
|
required this.icon,
|
||
|
|
required this.colorScheme,
|
||
|
|
required this.onTap,
|
||
|
|
});
|
||
|
|
|
||
|
|
final IconData icon;
|
||
|
|
final ColorScheme colorScheme;
|
||
|
|
final VoidCallback onTap;
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return GestureDetector(
|
||
|
|
onTap: onTap,
|
||
|
|
child: Container(
|
||
|
|
width: 32,
|
||
|
|
height: 32,
|
||
|
|
decoration: BoxDecoration(
|
||
|
|
color: colorScheme.surfaceContainerHigh,
|
||
|
|
borderRadius: BorderRadius.circular(16),
|
||
|
|
),
|
||
|
|
alignment: Alignment.center,
|
||
|
|
child: Icon(
|
||
|
|
icon,
|
||
|
|
size: 16,
|
||
|
|
color: colorScheme.onSurfaceVariant,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|