added custom welcome message to home screen

This commit is contained in:
Kima 2023-09-25 18:31:32 +02:00
parent 6212489001
commit 9cda8c5d29
2 changed files with 25 additions and 18 deletions

View File

@ -30,6 +30,7 @@ import 'package:provider/provider.dart';
import 'home_page.i18n.dart'; import 'home_page.i18n.dart';
import 'package:filcnaplo/ui/filter/widgets.dart'; import 'package:filcnaplo/ui/filter/widgets.dart';
import 'package:filcnaplo/ui/filter/sort.dart'; import 'package:filcnaplo/ui/filter/sort.dart';
import 'package:i18n_extension/i18n_extension.dart';
class HomePage extends StatefulWidget { class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key); const HomePage({Key? key}) : super(key: key);
@ -94,6 +95,13 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
void setGreeting() { void setGreeting() {
DateTime now = DateTime.now(); DateTime now = DateTime.now();
List<String> nameParts = user.displayName?.split(" ") ?? ["?"];
if (!settings.presentationMode) {
firstName = nameParts.length > 1 ? nameParts[1] : nameParts[0];
} else {
firstName = "János";
}
if (now.isBefore(DateTime(now.year, DateTime.august, 31)) && if (now.isBefore(DateTime(now.year, DateTime.august, 31)) &&
now.isAfter(DateTime(now.year, DateTime.june, 14))) { now.isAfter(DateTime(now.year, DateTime.june, 14))) {
greeting = "goodrest"; greeting = "goodrest";
@ -104,16 +112,16 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
Future.delayed(const Duration(seconds: 1)) Future.delayed(const Duration(seconds: 1))
.then((value) => mounted ? _confettiController?.play() : null); .then((value) => mounted ? _confettiController?.play() : null);
} }
} else if (now.month == user.student?.birth.month && // } else if (now.month == user.student?.birth.month &&
now.day == user.student?.birth.day) { // now.day == user.student?.birth.day) {
greeting = "happybirthday"; // greeting = "happybirthday";
if (NavigationScreen.of(context)?.init("confetti") ?? false) { // if (NavigationScreen.of(context)?.init("confetti") ?? false) {
_confettiController = // _confettiController =
ConfettiController(duration: const Duration(seconds: 3)); // ConfettiController(duration: const Duration(seconds: 3));
Future.delayed(const Duration(seconds: 1)) // Future.delayed(const Duration(seconds: 1))
.then((value) => mounted ? _confettiController?.play() : null); // .then((value) => mounted ? _confettiController?.play() : null);
} // }
} else if (now.isAfter(DateTime(now.year, DateTime.may, 28)) && } else if (now.isAfter(DateTime(now.year, DateTime.may, 28)) &&
now.isBefore(DateTime(now.year, DateTime.may, 30))) { now.isBefore(DateTime(now.year, DateTime.may, 30))) {
greeting = "refilcopen"; greeting = "refilcopen";
@ -130,6 +138,12 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
greeting = "merryxmas"; greeting = "merryxmas";
} else if (now.month == DateTime.january && now.day == 1) { } else if (now.month == DateTime.january && now.day == 1) {
greeting = "happynewyear"; greeting = "happynewyear";
} else if (settings.welcomeMessage.replaceAll(' ', '') != '') {
greeting = settings.welcomeMessage;
greeting = localizeFill(
settings.welcomeMessage,
[firstName],
);
} else if (now.hour >= 18) { } else if (now.hour >= 18) {
greeting = "goodevening"; greeting = "goodevening";
} else if (now.hour >= 10) { } else if (now.hour >= 10) {
@ -155,13 +169,6 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
setGreeting(); setGreeting();
List<String> nameParts = user.displayName?.split(" ") ?? ["?"];
if (!settings.presentationMode) {
firstName = nameParts.length > 1 ? nameParts[1] : nameParts[0];
} else {
firstName = "János";
}
return Scaffold( return Scaffold(
body: Stack( body: Stack(
children: [ children: [

View File

@ -45,10 +45,10 @@ class WelcomeMessagePanelButton extends StatelessWidget {
width: 100, width: 100,
child: Expanded( child: Expanded(
child: Text( child: Text(
settingsProvider.welcomeMessage != '' settingsProvider.welcomeMessage.replaceAll(' ', '') != ''
? localizeFill( ? localizeFill(
settingsProvider.welcomeMessage, settingsProvider.welcomeMessage,
[finalName, finalName, finalName], [finalName],
) )
: 'default'.i18n, : 'default'.i18n,
style: const TextStyle(fontSize: 14.0), style: const TextStyle(fontSize: 14.0),