Files
ReelShort/lib/pages/home/widgets/home_browse_header.dart
T

135 lines
3.6 KiB
Dart

// Author: fruit.com.cn
import 'package:flutter/material.dart';
import '../../../core/theme/app_colors.dart';
import '../../../core/theme/app_dimens.dart';
import '../../../l10n/app_localizations.dart';
const double _searchHeight = 36;
/// 首页固定顶栏:搜索、星期与头像入口。
class HomeBrowseHeader extends StatelessWidget {
const HomeBrowseHeader({
super.key,
required this.onSearch,
required this.onProfile,
});
final VoidCallback onSearch;
final VoidCallback onProfile;
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final weekday = _weekday(l10n);
return SizedBox(
height: AppDimens.contentHeaderHeight,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: AppDimens.pageHorizontal,
),
child: Row(
children: [
Expanded(child: _search(l10n, onSearch)),
const SizedBox(width: AppDimens.spaceSm),
_weekdayText(weekday),
const SizedBox(width: AppDimens.spaceSm),
_profile(l10n),
],
),
),
);
}
String _weekday(AppLocalizations l10n) {
return switch (DateTime.now().weekday) {
DateTime.monday => l10n.weekdayMon,
DateTime.tuesday => l10n.weekdayTue,
DateTime.wednesday => l10n.weekdayWed,
DateTime.thursday => l10n.weekdayThu,
DateTime.friday => l10n.weekdayFri,
DateTime.saturday => l10n.weekdaySat,
_ => l10n.weekdaySun,
};
}
Widget _search(AppLocalizations l10n, VoidCallback onTap) {
return Semantics(
button: true,
label: l10n.search,
child: InkWell(
key: const Key('home-search'),
onTap: onTap,
borderRadius: BorderRadius.circular(AppDimens.pillRadius),
child: Container(
height: _searchHeight,
padding: const EdgeInsets.symmetric(horizontal: AppDimens.spaceMd),
decoration: BoxDecoration(
color: AppColors.input,
borderRadius: BorderRadius.circular(AppDimens.pillRadius),
),
child: Row(
children: [
const Icon(
Icons.search_rounded,
color: AppColors.subtle,
size: 17,
),
const SizedBox(width: AppDimens.spaceSm),
Expanded(
child: Text(
l10n.searchDiscover,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.subtle,
fontSize: AppDimens.caption,
),
),
),
],
),
),
),
);
}
Widget _weekdayText(String value) {
return Text(
value,
key: const Key('home-weekday'),
style: const TextStyle(
color: AppColors.muted,
fontSize: AppDimens.caption,
fontWeight: FontWeight.w600,
),
);
}
Widget _profile(AppLocalizations l10n) {
return Semantics(
button: true,
label: l10n.myTab,
child: InkWell(
key: const Key('home-profile'),
customBorder: const CircleBorder(),
onTap: onProfile,
child: Container(
width: AppDimens.tapTarget,
height: AppDimens.tapTarget,
decoration: const BoxDecoration(
color: AppColors.card,
shape: BoxShape.circle,
),
child: const Icon(
Icons.person_rounded,
color: AppColors.onSurface,
size: AppDimens.accountIcon,
),
),
),
);
}
}