feat:重构模块
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter_common/widget/common_widget.dart';
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
import 'package:food_hub_app/provider/food_provider.dart';
|
||||
import 'package:food_hub_app/utils/index.dart';
|
||||
import 'package:food_hub_app/views/record_form.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -62,19 +63,16 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
Text(formatDateTime(provider.selectedDay, 'MM月dd日 EEEE')),
|
||||
SizedBox(height: 4),
|
||||
if (provider.selectRecordList.isEmpty)
|
||||
buildEmptyData()
|
||||
SizedBox(height: 100, child: buildEmptyData())
|
||||
else
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
itemCount: provider.selectRecordList.length,
|
||||
separatorBuilder: (context, index) => SizedBox(height: 8),
|
||||
itemBuilder: (context, index) {
|
||||
return _buildRecordItem(
|
||||
context,
|
||||
provider.selectRecordList[index],
|
||||
);
|
||||
},
|
||||
),
|
||||
Column(
|
||||
children:
|
||||
provider.selectRecordList.map((record) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: _buildRecordItem(context, record),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -112,7 +110,15 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
|
||||
provider.initRecordForm(record);
|
||||
provider.isEditing = true;
|
||||
Navigator.pushNamed(context, "/recordForm");
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
builder: (context) => RecordForm(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRecordItem(BuildContext context, FoodRecord record) {
|
||||
@@ -195,12 +201,15 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
}
|
||||
|
||||
Widget _buildContent(FoodProvider provider) {
|
||||
return Column(
|
||||
children: [
|
||||
CommonCard(child: _recipeCalendar(provider)),
|
||||
SizedBox(height: 8),
|
||||
Expanded(child: CommonCard(child: _dailyItem(context, provider))),
|
||||
],
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(bottom: 80),
|
||||
child: Column(
|
||||
children: [
|
||||
CommonCard(child: _recipeCalendar(provider)),
|
||||
const SizedBox(height: 8),
|
||||
CommonCard(child: _dailyItem(context, provider)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -208,13 +217,10 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<FoodProvider>();
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
if (provider.isLoading)
|
||||
buildLoadingIndicator()
|
||||
else
|
||||
_buildContent(provider),
|
||||
],
|
||||
);
|
||||
if (provider.isLoading) {
|
||||
return buildLoadingIndicator();
|
||||
}
|
||||
|
||||
return _buildContent(provider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_common/widget/common_widget.dart';
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
import 'package:food_hub_app/widgets/common/image.dart';
|
||||
import 'package:liquid_glass_widgets/liquid_glass_widgets.dart';
|
||||
|
||||
class RecipeCard extends StatelessWidget {
|
||||
final RecipeSummary recipe;
|
||||
@@ -17,14 +18,22 @@ class RecipeCard extends StatelessWidget {
|
||||
final List<String> imageUrls =
|
||||
recipe.recordList.reversed.map((record) => record.imageUrl).toList();
|
||||
|
||||
return CommonCard(
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return GlassCard(
|
||||
padding: EdgeInsetsGeometry.all(10),
|
||||
useOwnLayer: true,
|
||||
settings: LiquidGlassSettings(glassColor: colors.surface),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
CommonImage(imageUrls: imageUrls, index: 0),
|
||||
SizedBox(height: 8),
|
||||
_buildRecipeContent(context),
|
||||
InkWell(
|
||||
onTap: () => navigatorToRecipeDetail(context),
|
||||
child: _buildRecipeContent(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -32,6 +41,7 @@ class RecipeCard extends StatelessWidget {
|
||||
|
||||
Widget _buildRecipeContent(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -42,17 +52,10 @@ class RecipeCard extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
recipe.name,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
style: textTheme.titleMedium,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => navigatorToRecipeDetail(context),
|
||||
child: Icon(
|
||||
Icons.arrow_circle_right_sharp,
|
||||
color: colors.secondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
@@ -62,19 +65,13 @@ class RecipeCard extends StatelessWidget {
|
||||
_buildIconText(
|
||||
icon: Icons.food_bank,
|
||||
text: recipe.category,
|
||||
color: Color(0xFF6A5ACD),
|
||||
color: colors.primary,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_buildIconText(
|
||||
icon: Icons.thumb_up_alt_outlined,
|
||||
text: recipe.likeCount.toString(),
|
||||
color: Color(0xFFDC143C),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_buildIconText(
|
||||
icon: Icons.star_outline,
|
||||
text: recipe.favouriteCount.toString(),
|
||||
color: Color(0xFF20B2AA),
|
||||
icon: Icons.note_add,
|
||||
text: recipe.recordList.length.toString(),
|
||||
color: colors.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -22,56 +22,10 @@ class _RecipeListState extends State<RecipeList> {
|
||||
context.read<FoodProvider>().queryCategoryList();
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildSelectCategory(FoodProvider provider) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return Container(
|
||||
width: 140,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainer,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: DropdownButton<String>(
|
||||
value: provider.queryCategory,
|
||||
isExpanded: true,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
dropdownColor: colors.surfaceContainer,
|
||||
elevation: 6,
|
||||
underline: Container(),
|
||||
items:
|
||||
provider.categoryList.map((String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.primary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(value, style: TextStyle(fontSize: 14)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
provider.queryCategory = value!;
|
||||
provider.refreshRecipeList();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildRecipeList(FoodProvider provider) {
|
||||
return GridView.builder(
|
||||
padding: const EdgeInsets.only(bottom: 80),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
crossAxisSpacing: 8,
|
||||
@@ -91,8 +45,6 @@ class _RecipeListState extends State<RecipeList> {
|
||||
} else {
|
||||
return Column(
|
||||
children: [
|
||||
_buildSelectCategory(provider),
|
||||
SizedBox(height: 5),
|
||||
Expanded(child: _buildRecipeList(provider)),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -28,26 +28,24 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
SizedBox(width: 5),
|
||||
Text(
|
||||
record.date,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 6),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 0),
|
||||
child: CommonCard(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
record.name,
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
CommonImage(imageUrls: [record.imageUrl], index: 0),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
CommonCard(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
record.name,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
CommonImage(imageUrls: [record.imageUrl], index: 0),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20)
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -59,6 +57,7 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return Timeline.tileBuilder(
|
||||
padding: const EdgeInsets.only(bottom: 80),
|
||||
theme: TimelineThemeData(nodePosition: 0, indicatorPosition: 0),
|
||||
builder: TimelineTileBuilder.connected(
|
||||
itemCount: recordList.length,
|
||||
|
||||
Reference in New Issue
Block a user