106 lines
2.9 KiB
Dart
106 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:food_hub_app/provider/food_provider.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class AppActions extends StatefulWidget {
|
|
final int pageIndex;
|
|
|
|
const AppActions({super.key, required this.pageIndex});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => AppActionsState();
|
|
}
|
|
|
|
class AppActionsState extends State<AppActions> {
|
|
Widget _buildBottomSheetBody(FoodProvider provider) {
|
|
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),
|
|
if (widget.pageIndex == 0)
|
|
ListTile(
|
|
leading: Icon(Icons.book, color: colors.primary),
|
|
title: const Text('新增菜谱'),
|
|
onTap: () => _handleAddRecipe(provider),
|
|
),
|
|
if (widget.pageIndex == 0)
|
|
ListTile(
|
|
leading: Icon(Icons.note_add, color: colors.primary),
|
|
title: const Text('新增记录'),
|
|
onTap: () => _handleAddRecord(provider),
|
|
),
|
|
if (widget.pageIndex == 2)
|
|
ListTile(
|
|
leading: Icon(Icons.group, color: colors.primary),
|
|
title: const Text('发布朋友圈'),
|
|
onTap: () => _handleAddMoment(provider),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
void _onPressAdd(FoodProvider provider) {
|
|
if (widget.pageIndex == 0) {
|
|
showModalBottomSheet(
|
|
context: context,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
|
),
|
|
builder: (context) => _buildBottomSheetBody(provider),
|
|
);
|
|
}
|
|
|
|
if (widget.pageIndex == 2) {
|
|
_handleAddMoment(provider);
|
|
}
|
|
}
|
|
|
|
void _handleAddRecipe(FoodProvider provider) {
|
|
// provider.resetRecordForm();
|
|
// Navigator.pop(context);
|
|
// Navigator.pushNamed(context, "/recordForm");
|
|
}
|
|
|
|
void _handleAddRecord(FoodProvider provider) {
|
|
provider.resetRecordForm();
|
|
provider.isEditing = false;
|
|
Navigator.pop(context);
|
|
Navigator.pushNamed(context, "/recordForm");
|
|
}
|
|
|
|
void _handleAddMoment(FoodProvider provider) {
|
|
provider.resetMomentForm();
|
|
provider.isEditing = false;
|
|
Navigator.pushNamed(context, "/momentForm");
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final provider = context.watch<FoodProvider>();
|
|
|
|
return Row(
|
|
children: [
|
|
IconButton(
|
|
icon: Icon(Icons.search, color: Colors.white),
|
|
onPressed: () {
|
|
// 搜索功能
|
|
},
|
|
),
|
|
if (widget.pageIndex == 0 || widget.pageIndex == 2)
|
|
IconButton(
|
|
icon: Icon(Icons.add, color: Colors.white),
|
|
onPressed: () => _onPressAdd(provider),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|