From 51d8ef7707140a9356c093af829fbdc7bd3130d9 Mon Sep 17 00:00:00 2001 From: Kima Date: Sun, 21 Apr 2024 23:18:37 +0200 Subject: [PATCH] some livecard progress --- .../lib/pages/home/live_card/live_card.dart | 147 +++-- .../home/live_card/live_card_widget.dart | 517 ++++++++++-------- 2 files changed, 375 insertions(+), 289 deletions(-) diff --git a/refilc_mobile_ui/lib/pages/home/live_card/live_card.dart b/refilc_mobile_ui/lib/pages/home/live_card/live_card.dart index 1f205b2..1807d0b 100644 --- a/refilc_mobile_ui/lib/pages/home/live_card/live_card.dart +++ b/refilc_mobile_ui/lib/pages/home/live_card/live_card.dart @@ -3,6 +3,8 @@ import 'package:refilc/api/providers/user_provider.dart'; import 'package:refilc/helpers/subject.dart'; import 'package:refilc/icons/filc_icons.dart'; import 'package:refilc/models/settings.dart'; +import 'package:refilc_mobile_ui/common/round_border_icon.dart'; +import 'package:refilc_mobile_ui/common/splitted_panel/splitted_panel.dart'; import 'package:refilc_mobile_ui/pages/home/live_card/heads_up_countdown.dart'; import 'package:refilc_mobile_ui/screens/summary/summary_screen.dart'; import 'package:flutter/material.dart'; @@ -54,7 +56,7 @@ class LiveCardStateA extends State { Duration bellDelay = liveCard.delay; // test - // liveCard.currentState = LiveCardState.morning; + liveCard.currentState = LiveCardState.morning; switch (liveCard.currentState) { case LiveCardState.summary: @@ -102,60 +104,113 @@ class LiveCardStateA extends State { case LiveCardState.morning: child = LiveCardWidget( key: const Key('livecard.morning'), - title: DateFormat("EEEE", I18n.of(context).locale.toString()) - .format(DateTime.now()) - .capital(), - icon: FeatherIcons.sun, + // title: DateFormat("EEEE", I18n.of(context).locale.toString()) + // .format(DateTime.now()) + // .capital(), + // icon: FeatherIcons.sun, onTap: () async { await MapsLauncher.launchQuery( '${_userProvider.student?.school.city ?? ''} ${_userProvider.student?.school.name ?? ''}'); }, - description: liveCard.nextLesson != null - ? Text.rich( - TextSpan( + // description: liveCard.nextLesson != null + // ? Text.rich( + // TextSpan( + // children: [ + // TextSpan(text: "first_lesson_1".i18n), + // TextSpan( + // text: liveCard.nextLesson!.subject.renamedTo ?? + // liveCard.nextLesson!.subject.name.capital(), + // style: TextStyle( + // fontWeight: FontWeight.w600, + // color: Theme.of(context) + // .colorScheme + // .secondary + // .withOpacity(.85), + // fontStyle: liveCard.nextLesson!.subject.isRenamed && + // settingsProvider.renamedSubjectsItalics + // ? FontStyle.italic + // : null), + // ), + // TextSpan(text: "first_lesson_2".i18n), + // TextSpan( + // text: liveCard.nextLesson!.room.capital(), + // style: TextStyle( + // fontWeight: FontWeight.w600, + // color: Theme.of(context) + // .colorScheme + // .secondary + // .withOpacity(.85), + // ), + // ), + // TextSpan(text: "first_lesson_3".i18n), + // TextSpan( + // text: DateFormat('H:mm') + // .format(liveCard.nextLesson!.start), + // style: TextStyle( + // fontWeight: FontWeight.w600, + // color: Theme.of(context) + // .colorScheme + // .secondary + // .withOpacity(.85), + // ), + // ), + // TextSpan(text: "first_lesson_4".i18n), + // ], + // ), + // ) + // : null, + children: liveCard.nextLesson == null + ? [ + SplittedPanel( + hasShadow: false, + padding: EdgeInsets.zero, + cardPadding: const EdgeInsets.all(18.0), + spacing: 8.0, children: [ - TextSpan(text: "first_lesson_1".i18n), - TextSpan( - text: liveCard.nextLesson!.subject.renamedTo ?? - liveCard.nextLesson!.subject.name.capital(), - style: TextStyle( - fontWeight: FontWeight.w600, - color: Theme.of(context) - .colorScheme - .secondary - .withOpacity(.85), - fontStyle: liveCard.nextLesson!.subject.isRenamed && - settingsProvider.renamedSubjectsItalics - ? FontStyle.italic - : null), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('Hamarosan kezdődik az első órád!'), + Text('1 óra 32 perc 26 másodperc'), + ], ), - TextSpan(text: "first_lesson_2".i18n), - TextSpan( - text: liveCard.nextLesson!.room.capital(), - style: TextStyle( - fontWeight: FontWeight.w600, - color: Theme.of(context) - .colorScheme - .secondary - .withOpacity(.85), - ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + children: [ + Icon( + SubjectIcon.resolveVariant( + context: context, + subjectName: 'matekgeci', + ), + ), + const SizedBox(width: 12.0), + Text( + 'matekfasz', + style: TextStyle( + fontSize: 16.0, + fontWeight: FontWeight.w600, + ), + ), + ], + ), + Row( + children: [ + Text( + '8:00-8:45', + style: TextStyle( + fontSize: 12.0, + fontWeight: FontWeight.w500, + ), + ), + ], + ), + ], ), - TextSpan(text: "first_lesson_3".i18n), - TextSpan( - text: DateFormat('H:mm') - .format(liveCard.nextLesson!.start), - style: TextStyle( - fontWeight: FontWeight.w600, - color: Theme.of(context) - .colorScheme - .secondary - .withOpacity(.85), - ), - ), - TextSpan(text: "first_lesson_4".i18n), ], ), - ) + ] : null, ); break; diff --git a/refilc_mobile_ui/lib/pages/home/live_card/live_card_widget.dart b/refilc_mobile_ui/lib/pages/home/live_card/live_card_widget.dart index a9a009a..90f5cdf 100644 --- a/refilc_mobile_ui/lib/pages/home/live_card/live_card_widget.dart +++ b/refilc_mobile_ui/lib/pages/home/live_card/live_card_widget.dart @@ -1,3 +1,4 @@ +import 'package:i18n_extension/i18n_extension.dart'; import 'package:refilc/models/settings.dart'; import 'package:refilc/theme/colors/colors.dart'; import 'package:refilc_mobile_ui/common/progress_bar.dart'; @@ -26,6 +27,7 @@ class LiveCardWidget extends StatefulWidget { this.progressAccuracy = ProgressAccuracy.minutes, this.onProgressTap, this.onTap, + this.children, }); final bool isEvent; @@ -43,6 +45,7 @@ class LiveCardWidget extends StatefulWidget { final ProgressAccuracy? progressAccuracy; final Function()? onProgressTap; final Function()? onTap; + final List? children; @override State createState() => _LiveCardWidgetState(); @@ -63,11 +66,17 @@ class _LiveCardWidgetState extends State { curve: Curves.easeInOutBack, duration: const Duration(milliseconds: 300), child: Container( - margin: const EdgeInsets.symmetric(vertical: 2.0), - padding: const EdgeInsets.all(12.0), + margin: widget.children == null + ? const EdgeInsets.symmetric(vertical: 2.0) + : EdgeInsets.zero, + padding: widget.children == null + ? const EdgeInsets.all(12.0) + : EdgeInsets.zero, decoration: BoxDecoration( // color: Theme.of(context).colorScheme.background, - color: Colors.transparent, + color: widget.children != null + ? Colors.transparent + : Theme.of(context).colorScheme.background, borderRadius: BorderRadius.circular(16.0), boxShadow: [ if (Provider.of(context, listen: false) @@ -80,7 +89,9 @@ class _LiveCardWidgetState extends State { ], ), child: Container( - padding: const EdgeInsets.symmetric(horizontal: 6.0), + padding: widget.children == null + ? const EdgeInsets.symmetric(horizontal: 6.0) + : EdgeInsets.zero, child: OverflowBox( maxHeight: 96.0, child: widget.isEvent @@ -137,251 +148,271 @@ class _LiveCardWidgetState extends State { ), ], ) - : Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - Expanded( - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (widget.leading != null) - Padding( - padding: const EdgeInsets.only( - right: 12.0, top: 8.0), - child: Text( - widget.leading!, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 32.0, - fontWeight: FontWeight.w600, - color: Theme.of(context) - .colorScheme - .secondary, - ), - ), - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: - MainAxisAlignment.spaceAround, - children: [ - Row( - children: [ - if (widget.title != null) - Expanded( - child: Text.rich( - TextSpan( - children: [ - TextSpan( - text: widget.title!, - style: TextStyle( - fontStyle: widget - .titleItalic - ? FontStyle.italic - : null)), - if (widget.subtitle != null) - WidgetSpan( - child: Container( - margin: const EdgeInsets - .only( - left: 6.0, - bottom: 3.0), - padding: - const EdgeInsets - .symmetric( - horizontal: 4.0, - vertical: 2.0), - decoration: - BoxDecoration( - color: Theme.of( - context) - .colorScheme - .secondary - .withOpacity(.3), - borderRadius: - BorderRadius - .circular( - 4.0), - ), - child: Text( - widget.subtitle!, - style: TextStyle( - height: 1.2, - fontSize: 14.0, - fontWeight: - FontWeight.w600, - color: Theme.of( - context) - .colorScheme - .secondary, - ), - ), - ), - ), - ], - ), - style: const TextStyle( - fontWeight: FontWeight.w600, - fontSize: 22.0), - maxLines: 1, - softWrap: false, - overflow: TextOverflow.ellipsis, - ), - ), - if (widget.title != null) - const SizedBox(width: 6.0), - if (widget.icon != null) - Padding( - padding: const EdgeInsets.symmetric( - vertical: 4.0), - child: Icon( - widget.icon, - size: 26.0, - color: AppColors.of(context) - .text - .withOpacity(.75), - ), - ), - ], - ), - if (widget.description != null) - DefaultTextStyle( - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - fontWeight: FontWeight.w500, - fontSize: 16.0, - height: 1.0, - color: AppColors.of(context) - .text - .withOpacity(.75), - ), - maxLines: - !(widget.nextSubject == null && - widget.progressCurrent == - null && - widget.progressMax == null) - ? 1 - : 2, - softWrap: false, - overflow: TextOverflow.ellipsis, - child: widget.description!, - ), - ], - ), - ), - ], - ), - ), - if (!(widget.nextSubject == null && - widget.progressCurrent == null && - widget.progressMax == null)) - Padding( - padding: const EdgeInsets.only(top: 8.0), - child: Row( - children: [ - if (widget.nextSubject != null) - const Icon(FeatherIcons.arrowRight, - size: 12.0), - if (widget.nextSubject != null) - const SizedBox(width: 4.0), - if (widget.nextSubject != null) - Expanded( - child: Text.rich( - TextSpan( - children: [ - TextSpan( - text: widget.nextSubject!, - style: TextStyle( - fontStyle: - widget.nextSubjectItalic - ? FontStyle.italic - : null)), - if (widget.nextRoom != null) - WidgetSpan( - child: Container( - margin: const EdgeInsets.only( - left: 4.0), - padding: - const EdgeInsets.symmetric( - horizontal: 3.0, - vertical: 1.5), - decoration: BoxDecoration( - color: Theme.of(context) - .colorScheme - .secondary - .withOpacity(.25), - borderRadius: - BorderRadius.circular( - 4.0), - ), - child: Text( - widget.nextRoom!, - style: TextStyle( - height: 1.1, - fontSize: 12.0, - fontWeight: FontWeight.w600, - color: Theme.of(context) - .colorScheme - .secondary - .withOpacity(.9), - ), - ), - ), - ), - ], - ), - style: TextStyle( - color: AppColors.of(context) - .text - .withOpacity(.8), - fontWeight: FontWeight.w600, - ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - softWrap: false, - ), - ), - if (widget.nextRoom == null && - widget.nextSubject == null) - const Spacer(), - if (widget.progressCurrent != null && - widget.progressMax != null) - GestureDetector( - onTap: widget.onProgressTap, - child: Container( - color: Colors.transparent, + : widget.children != null + ? Column( + children: widget.children ?? [], + ) + : Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Expanded( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (widget.leading != null) + Padding( + padding: const EdgeInsets.only( + right: 12.0, top: 8.0), child: Text( - "remaining ${widget.progressAccuracy == ProgressAccuracy.minutes ? 'min' : 'sec'}" - .plural((widget.progressMax! - - widget.progressCurrent!) - .round()), - maxLines: 1, + widget.leading!, + textAlign: TextAlign.center, style: TextStyle( - fontWeight: FontWeight.w500, - color: AppColors.of(context) - .text - .withOpacity(.75), + fontSize: 32.0, + fontWeight: FontWeight.w600, + color: Theme.of(context) + .colorScheme + .secondary, ), ), ), - ) - ], + Expanded( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + mainAxisAlignment: + MainAxisAlignment.spaceAround, + children: [ + Row( + children: [ + if (widget.title != null) + Expanded( + child: Text.rich( + TextSpan( + children: [ + TextSpan( + text: widget.title!, + style: TextStyle( + fontStyle: widget + .titleItalic + ? FontStyle + .italic + : null)), + if (widget.subtitle != + null) + WidgetSpan( + child: Container( + margin: + const EdgeInsets + .only( + left: 6.0, + bottom: + 3.0), + padding: + const EdgeInsets + .symmetric( + horizontal: + 4.0, + vertical: + 2.0), + decoration: + BoxDecoration( + color: Theme.of( + context) + .colorScheme + .secondary + .withOpacity( + .3), + borderRadius: + BorderRadius + .circular( + 4.0), + ), + child: Text( + widget.subtitle!, + style: TextStyle( + height: 1.2, + fontSize: 14.0, + fontWeight: + FontWeight + .w600, + color: Theme.of( + context) + .colorScheme + .secondary, + ), + ), + ), + ), + ], + ), + style: const TextStyle( + fontWeight: + FontWeight.w600, + fontSize: 22.0), + maxLines: 1, + softWrap: false, + overflow: + TextOverflow.ellipsis, + ), + ), + if (widget.title != null) + const SizedBox(width: 6.0), + if (widget.icon != null) + Padding( + padding: + const EdgeInsets.symmetric( + vertical: 4.0), + child: Icon( + widget.icon, + size: 26.0, + color: AppColors.of(context) + .text + .withOpacity(.75), + ), + ), + ], + ), + if (widget.description != null) + DefaultTextStyle( + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + fontWeight: FontWeight.w500, + fontSize: 16.0, + height: 1.0, + color: AppColors.of(context) + .text + .withOpacity(.75), + ), + maxLines: + !(widget.nextSubject == null && + widget.progressCurrent == + null && + widget.progressMax == + null) + ? 1 + : 2, + softWrap: false, + overflow: TextOverflow.ellipsis, + child: widget.description!, + ), + ], + ), + ), + ], + ), ), - ), - if (widget.progressCurrent != null && - widget.progressMax != null) - Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0), - child: ProgressBar( - value: widget.progressCurrent! / - widget.progressMax!), - ) - ], - ), + if (!(widget.nextSubject == null && + widget.progressCurrent == null && + widget.progressMax == null)) + Padding( + padding: const EdgeInsets.only(top: 8.0), + child: Row( + children: [ + if (widget.nextSubject != null) + const Icon(FeatherIcons.arrowRight, + size: 12.0), + if (widget.nextSubject != null) + const SizedBox(width: 4.0), + if (widget.nextSubject != null) + Expanded( + child: Text.rich( + TextSpan( + children: [ + TextSpan( + text: widget.nextSubject!, + style: TextStyle( + fontStyle: widget + .nextSubjectItalic + ? FontStyle.italic + : null)), + if (widget.nextRoom != null) + WidgetSpan( + child: Container( + margin: + const EdgeInsets.only( + left: 4.0), + padding: const EdgeInsets + .symmetric( + horizontal: 3.0, + vertical: 1.5), + decoration: BoxDecoration( + color: Theme.of(context) + .colorScheme + .secondary + .withOpacity(.25), + borderRadius: + BorderRadius.circular( + 4.0), + ), + child: Text( + widget.nextRoom!, + style: TextStyle( + height: 1.1, + fontSize: 12.0, + fontWeight: + FontWeight.w600, + color: Theme.of(context) + .colorScheme + .secondary + .withOpacity(.9), + ), + ), + ), + ), + ], + ), + style: TextStyle( + color: AppColors.of(context) + .text + .withOpacity(.8), + fontWeight: FontWeight.w600, + ), + maxLines: 1, + overflow: TextOverflow.ellipsis, + softWrap: false, + ), + ), + if (widget.nextRoom == null && + widget.nextSubject == null) + const Spacer(), + if (widget.progressCurrent != null && + widget.progressMax != null) + GestureDetector( + onTap: widget.onProgressTap, + child: Container( + color: Colors.transparent, + child: Text( + "remaining ${widget.progressAccuracy == ProgressAccuracy.minutes ? 'min' : 'sec'}" + .plural((widget.progressMax! - + widget.progressCurrent!) + .round()), + maxLines: 1, + style: TextStyle( + fontWeight: FontWeight.w500, + color: AppColors.of(context) + .text + .withOpacity(.75), + ), + ), + ), + ) + ], + ), + ), + if (widget.progressCurrent != null && + widget.progressMax != null) + Padding( + padding: + const EdgeInsets.symmetric(vertical: 4.0), + child: ProgressBar( + value: widget.progressCurrent! / + widget.progressMax!), + ) + ], + ), ), ), ),