125 lines
3.2 KiB
Dart
125 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:food_hub_app/models/layout.dart';
|
|
import 'package:food_hub_app/views/moment.dart';
|
|
import 'package:food_hub_app/views/profile.dart';
|
|
import 'package:food_hub_app/views/record.dart';
|
|
import 'package:food_hub_app/views/stats.dart';
|
|
|
|
final List<PageInfo> pageInfos = [
|
|
PageInfo(
|
|
label: "记录",
|
|
icon: Icons.home_outlined,
|
|
activeIcon: Icons.home,
|
|
page: RecordPage(),
|
|
),
|
|
PageInfo(
|
|
label: "统计",
|
|
icon: Icons.pie_chart_outline,
|
|
activeIcon: Icons.pie_chart,
|
|
page: StatsPage(),
|
|
),
|
|
PageInfo(
|
|
label: "朋友圈",
|
|
icon: Icons.group_outlined,
|
|
activeIcon: Icons.group,
|
|
page: MomentPage(),
|
|
),
|
|
PageInfo(
|
|
label: "我的",
|
|
icon: Icons.account_circle_outlined,
|
|
activeIcon: Icons.account_circle,
|
|
page: ProfilePage(),
|
|
),
|
|
];
|
|
|
|
Widget buildBottomNavBar({
|
|
required int currentIndex,
|
|
required Function(int) onTap,
|
|
}) {
|
|
final List<BottomNavigationBarItem> items =
|
|
pageInfos
|
|
.map(
|
|
(item) => BottomNavigationBarItem(
|
|
icon: Icon(item.icon),
|
|
activeIcon: Icon(item.activeIcon),
|
|
label: item.label,
|
|
),
|
|
)
|
|
.toList();
|
|
|
|
return BottomNavigationBar(
|
|
currentIndex: currentIndex,
|
|
iconSize: 25,
|
|
type: BottomNavigationBarType.fixed,
|
|
backgroundColor: Colors.white,
|
|
items: items,
|
|
onTap: onTap,
|
|
);
|
|
}
|
|
|
|
void buildBottomSheet(BuildContext context) {
|
|
showModalBottomSheet(
|
|
context: context,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
|
),
|
|
builder: (context) => buildBottomSheetBody(context),
|
|
);
|
|
}
|
|
|
|
Widget buildBottomSheetBody(BuildContext context) {
|
|
final colors = Theme.of(context).colorScheme;
|
|
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const SizedBox(height: 8),
|
|
const Text(
|
|
'请选择操作',
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 10),
|
|
ListTile(
|
|
leading: Icon(Icons.book, color: colors.primary),
|
|
title: const Text('新增菜谱'),
|
|
onTap: () {
|
|
Navigator.pop(context);
|
|
_handleAddRecipe(context);
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: Icon(Icons.note_add, color: colors.primary),
|
|
title: const Text('新增记录'),
|
|
onTap: () {
|
|
Navigator.pop(context);
|
|
Navigator.pushNamed(context, "/recordForm");
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: Icon(Icons.group, color: colors.primary),
|
|
title: const Text('发布朋友圈'),
|
|
onTap: () {
|
|
Navigator.pop(context);
|
|
_handleAddRecord(context);
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 处理添加菜谱
|
|
void _handleAddRecipe(BuildContext context) {
|
|
// 这里添加跳转或处理添加菜谱的逻辑
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(const SnackBar(content: Text('添加菜谱功能')));
|
|
}
|
|
|
|
// 处理添加记录
|
|
void _handleAddRecord(BuildContext context) {
|
|
// 这里添加跳转或处理添加记录的逻辑
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(const SnackBar(content: Text('添加记录功能')));
|
|
}
|