125 lines
3.4 KiB
Dart
125 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:food_hub_app/models/layout.dart';
|
|
import 'package:food_hub_app/models/recipe.dart';
|
|
import 'package:food_hub_app/provider/food_provider.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';
|
|
|
|
import 'package:provider/provider.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;
|
|
final provider = context.watch<FoodProvider>();
|
|
|
|
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: () => _handleAddRecipe(context, provider),
|
|
),
|
|
ListTile(
|
|
leading: Icon(Icons.note_add, color: colors.primary),
|
|
title: const Text('新增记录'),
|
|
onTap: () => _handleAddRecord(context, provider),
|
|
),
|
|
ListTile(
|
|
leading: Icon(Icons.group, color: colors.primary),
|
|
title: const Text('发布朋友圈'),
|
|
onTap: () => _handleAddMoment(context, provider),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
void _handleAddRecipe(BuildContext context, FoodProvider provider) {
|
|
// provider.resetRecordForm();
|
|
// Navigator.pop(context);
|
|
// Navigator.pushNamed(context, "/recordForm");
|
|
}
|
|
|
|
void _handleAddRecord(BuildContext context, FoodProvider provider) {
|
|
provider.resetRecordForm();
|
|
provider.isEditing = false;
|
|
Navigator.pop(context);
|
|
Navigator.pushNamed(context, "/recordForm");
|
|
}
|
|
|
|
void _handleAddMoment(BuildContext context, FoodProvider provider) {
|
|
provider.resetRecordForm();
|
|
provider.isEditing = false;
|
|
Navigator.pop(context);
|
|
Navigator.pushNamed(context, "/momentForm");
|
|
}
|