From aa9724102b5f74a68e69303294b620c58f1c905f Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 28 Nov 2024 00:04:45 +0800 Subject: [PATCH] :sparkles: Birthday celebration --- assets/translations/en.json | 3 ++- assets/translations/zh.json | 3 ++- lib/screens/home.dart | 29 ++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 0cd4d45..9d9a7e5 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -267,5 +267,6 @@ "dailyCheckNegativeHint5": "Gaming", "dailyCheckNegativeHint5Description": "Lost connection at a crucial moment", "dailyCheckNegativeHint6": "Going out", - "dailyCheckNegativeHint6Description": "Forgot your umbrella and got caught in the rain" + "dailyCheckNegativeHint6Description": "Forgot your umbrella and got caught in the rain", + "happyBirthday": "Happy birthday, {}!" } diff --git a/assets/translations/zh.json b/assets/translations/zh.json index 742accb..c5fe4b7 100644 --- a/assets/translations/zh.json +++ b/assets/translations/zh.json @@ -269,5 +269,6 @@ "dailyCheckNegativeHint5": "打游戏", "dailyCheckNegativeHint5Description": "关键时刻断网", "dailyCheckNegativeHint6": "出门", - "dailyCheckNegativeHint6Description": "忘带伞遇上大雨" + "dailyCheckNegativeHint6Description": "忘带伞遇上大雨", + "happyBirthday": "生日快乐,{}!" } diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 8a29d09..a01aef4 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -7,6 +7,7 @@ import 'package:provider/provider.dart'; import 'package:styled_widget/styled_widget.dart'; import 'package:flutter/material.dart'; import 'package:surface/providers/sn_network.dart'; +import 'package:surface/providers/userinfo.dart'; import 'package:surface/types/check_in.dart'; import 'package:surface/widgets/dialog.dart'; @@ -60,6 +61,7 @@ class _HomeScreenState extends State { const SizedBox(), ], ), + _HomeDashSpecialDayWidget().padding(top: 8, horizontal: 8), StaggeredGrid.count( crossAxisCount: 2, mainAxisSpacing: 8, @@ -71,7 +73,7 @@ class _HomeScreenState extends State { child: card.child, ); }).toList(), - ).padding(all: 8), + ).padding(horizontal: 8), ], ), ), @@ -79,6 +81,31 @@ class _HomeScreenState extends State { } } +class _HomeDashSpecialDayWidget extends StatelessWidget { + const _HomeDashSpecialDayWidget({super.key}); + + @override + Widget build(BuildContext context) { + final ua = context.watch(); + final today = DateTime.now(); + final birthday = ua.user?.profile?.birthday?.toLocal(); + final isBirthday = birthday != null && + birthday.day == today.day && + birthday.month == today.month; + return Column( + children: [ + if (isBirthday) + Card( + child: ListTile( + leading: Text('🎂').fontSize(24), + title: Text('happyBirthday').tr(args: [ua.user?.nick ?? 'user']), + ), + ).padding(bottom: 8), + ], + ); + } +} + class _HomeDashCheckInWidget extends StatefulWidget { const _HomeDashCheckInWidget({super.key});