feat:增加主题色模块
This commit is contained in:
@@ -43,7 +43,7 @@ class BuildCard extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
// border: Border.all(color: colors.outline.withAlpha(50), width: 1),
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
@@ -62,16 +62,18 @@ Widget buildToggleSwitch<T extends Enum>({
|
||||
required List<String> labels,
|
||||
required ValueChanged<T> onTabChanged,
|
||||
}) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return ToggleSwitch(
|
||||
minWidth: 90.0,
|
||||
minHeight: 40.0,
|
||||
initialLabelIndex: tabValues.indexOf(currentTab),
|
||||
totalSwitches: tabValues.length,
|
||||
labels: labels,
|
||||
activeBgColor: [Theme.of(context).colorScheme.primary],
|
||||
activeBgColor: [colors.primary],
|
||||
activeFgColor: Colors.white,
|
||||
inactiveBgColor: Colors.grey.shade200,
|
||||
inactiveFgColor: Colors.grey.shade700,
|
||||
inactiveBgColor: colors.surfaceContainer,
|
||||
inactiveFgColor: colors.onSurface,
|
||||
cornerRadius: 12.0,
|
||||
customTextStyles: [TextStyle(fontSize: 12, fontWeight: FontWeight.w500)],
|
||||
onToggle: (index) {
|
||||
@@ -111,7 +113,7 @@ Widget buildTag(BuildContext context, String title) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Color.lerp(colors.primary, Colors.white, 0.8),
|
||||
color: colors.primary.withAlpha(60),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(title, style: TextStyle(color: colors.primary)),
|
||||
|
||||
@@ -17,85 +17,60 @@ class RecipeCard extends StatelessWidget {
|
||||
final List<String> imageUrls =
|
||||
recipe.recordList.reversed.map((record) => record.imageUrl).toList();
|
||||
|
||||
Widget buildRecipeContent(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
recipe.name,
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
_buildIconText(
|
||||
icon: Icons.food_bank,
|
||||
text: recipe.category,
|
||||
color: Color(0xFF6A5ACD),
|
||||
),
|
||||
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),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_buildIconText(
|
||||
icon: Icons.comment_outlined,
|
||||
text: recipe.commentCount.toString(),
|
||||
color: Color(0xFFDAC570),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
_buildIconText(
|
||||
icon: Icons.date_range,
|
||||
text: recipe.recordList[0].date,
|
||||
color: Color(0xFF32CD32),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return BuildCard(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
buildNetworkImage(context, imageUrls, 0),
|
||||
SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onTap: () => navigatorToRecipeDetail(context),
|
||||
child: buildRecipeContent(context),
|
||||
child: _buildRecipeContent(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRecipeContent() {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
recipe.name,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_buildIconText(
|
||||
icon: Icons.food_bank,
|
||||
text: recipe.category,
|
||||
color: Color(0xFF6A5ACD),
|
||||
),
|
||||
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),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 通用图标文本组件
|
||||
Widget _buildIconText({
|
||||
required IconData icon,
|
||||
|
||||
@@ -82,9 +82,14 @@ class _RecipeListState extends State<RecipeList> {
|
||||
_buildSelectCategory(provider),
|
||||
SizedBox(height: 5),
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
child: GridView.builder(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2, // 每行2个
|
||||
crossAxisSpacing: 8, // 水平间距
|
||||
mainAxisSpacing: 8, // 垂直间距
|
||||
childAspectRatio: 0.9,
|
||||
),
|
||||
itemCount: provider.recipeSummaryList.length,
|
||||
separatorBuilder: (context, index) => SizedBox(height: 8),
|
||||
itemBuilder: (context, index) {
|
||||
return RecipeCard(recipe: provider.recipeSummaryList[index]);
|
||||
},
|
||||
|
||||
@@ -16,35 +16,39 @@ class RecipeTimeline extends StatefulWidget {
|
||||
|
||||
class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
Widget buildTimelineCard(BuildContext context, FoodRecord record) {
|
||||
return BuildCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.date_range,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
Text(
|
||||
record.date,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.date_range,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
Text(
|
||||
record.date,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 6),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 0),
|
||||
child: BuildCard(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
record.name,
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
buildNetworkImage(context, [record.imageUrl], 0),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
record.name,
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
buildNetworkImage(context, [record.imageUrl], 0),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,7 +73,7 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
},
|
||||
contentsBuilder: (context, index) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(4),
|
||||
padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 8),
|
||||
child: buildTimelineCard(context, recordList[index]),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user