Skip to content

Commit

Permalink
Merge pull request #148 from krolmic/feat/change-years-in-graph-view
Browse files Browse the repository at this point in the history
Feat/change years in graph view
  • Loading branch information
krolmic authored Oct 15, 2024
2 parents 383b36b + bfcc622 commit e606d1e
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 137 deletions.
65 changes: 22 additions & 43 deletions tracking_flutter/lib/calendar/view/widgets/calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _CalendarTheme {
color: AppColors.darkBlue,
);

static const calendarPrevAndNextButtonsColor = AppColors.grey;
static const calendarPrevAndNextButtonsColor = AppColors.primarySwatch;

static const todayButtonColor = AppColors.primarySwatch;

Expand Down Expand Up @@ -251,50 +251,29 @@ class _CalendarHeader extends StatelessWidget {
style: Theme.of(context).textTheme.headlineSmall,
),
const Spacer(),
Material(
color: Colors.transparent,
child: InkWell(
onTap: () async {
await onButtonPressed(
date: targetMonthDate.previousMonth,
context: context,
);
},
borderRadius: BorderRadius.circular(20),
child: Container(
alignment: Alignment.center,
padding: const EdgeInsets.only(
left: 7,
right: 8,
top: 8,
bottom: 8,
),
child: Icon(
Iconsax.arrow_left_2_outline,
color: _CalendarTheme.calendarPrevAndNextButtonsColor,
size: Theme.of(context).appBarTheme.iconTheme!.size,
),
),
IconButton(
color: _CalendarTheme.calendarPrevAndNextButtonsColor,
icon: Icon(
Iconsax.arrow_left_2_outline,
size: Theme.of(context).appBarTheme.iconTheme!.size,
),
),
const HorizontalSpacing.extraLarge(),
Material(
color: Colors.transparent,
child: InkWell(
onTap: () => onButtonPressed(
date: targetMonthDate.nextMonth,
onPressed: () async {
await onButtonPressed(
date: targetMonthDate.previousMonth,
context: context,
),
borderRadius: BorderRadius.circular(20),
child: Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(8),
child: Icon(
Iconsax.arrow_right_3_outline,
color: _CalendarTheme.calendarPrevAndNextButtonsColor,
size: Theme.of(context).appBarTheme.iconTheme!.size,
),
),
);
},
),
const HorizontalSpacing.large(),
IconButton(
color: _CalendarTheme.calendarPrevAndNextButtonsColor,
icon: Icon(
Iconsax.arrow_right_3_outline,
size: Theme.of(context).appBarTheme.iconTheme!.size,
),
onPressed: () => onButtonPressed(
date: targetMonthDate.nextMonth,
context: context,
),
),
],
Expand Down
1 change: 0 additions & 1 deletion tracking_flutter/lib/graph/bloc/graph_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class GraphBloc extends Bloc<GraphEvent, GraphState> {
settings: state.settings.copyWith(
timeRangeMode: mode,
),
targetDate: const GraphTargetDateState.initial(),
),
);
await _loadMoods(emit);
Expand Down
10 changes: 8 additions & 2 deletions tracking_flutter/lib/graph/view/graph_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -133,7 +135,7 @@ class _GraphView extends StatelessWidget {
const VerticalSpacing.large(),
const Padding(
padding: EdgeInsets.symmetric(
horizontal: horizontalPaddingSmall,
horizontal: viewPaddingHorizontal + horizontalPaddingLarge,
),
child: _GraphHeader(),
),
Expand All @@ -150,6 +152,8 @@ class _GraphView extends StatelessWidget {
return _MonthsSelection(
currentMonth: dateTimeNow.month,
selectedMonth: setTargetDate.month,
disableMonths: setTargetDate.year == dateTimeNow.year,
currentYear: setTargetDate.year,
onMonthSelected: (month) {
context.read<GraphBloc>().add(
GraphEvent.targetDateChanged(
Expand All @@ -163,6 +167,8 @@ class _GraphView extends StatelessWidget {
numberOfWeeks: setTargetDate.numberOfWeeksInYear,
currentWeek: dateTimeNow.weekNumber,
selectedWeek: setTargetDate.weekNumber,
disableWeeks: setTargetDate.year == dateTimeNow.year,
currentYear: setTargetDate.year,
onWeekSelected: (week) {
context.read<GraphBloc>().add(
GraphEvent.targetDateChanged(
Expand All @@ -175,7 +181,7 @@ class _GraphView extends StatelessWidget {
}
},
),
const VerticalSpacing.extraLarge(),
const VerticalSpacing.extraExtraLarge(),
Container(
padding:
const EdgeInsets.symmetric(horizontal: viewPaddingHorizontal),
Expand Down
119 changes: 74 additions & 45 deletions tracking_flutter/lib/graph/view/widgets/graph_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,86 @@ class _GraphHeader extends StatelessWidget {
Widget build(BuildContext context) {
final translations = AppLocalizations.of(context)!;

return SizedBox(
height: 30,
child: Stack(
children: [
Positioned.fill(
child: Center(
child: Text(
DateTime.now().year.toString(),
style: Theme.of(context).textTheme.headlineSmall,
),
return BlocBuilder<GraphBloc, GraphState>(
buildWhen: (previous, current) =>
previous.targetDate.date.year != current.targetDate.date.year,
builder: (context, state) {
final nextButtonDisabled =
state.targetDate.date.year == DateTime.now().year;

return Row(
children: [
Text(
state.targetDate.date.year.toString(),
style: Theme.of(context).textTheme.headlineSmall,
),
),
Positioned.fill(
child: Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: horizontalPaddingMedium,
),
child: IconButton(
color: AppColors.primarySwatch,
icon: Icon(
Iconsax.setting_4_outline,
size: Theme.of(context).appBarTheme.iconTheme!.size,
const Spacer(),
IconButton(
color: AppColors.primarySwatch,
icon: Icon(
Iconsax.setting_4_outline,
size: Theme.of(context).appBarTheme.iconTheme!.size,
),
onPressed: () {
RevenueCatUIHelper.showPaywallIfNecessary(
requiresSubscriptionCallback: () async {
await showSettingsDialog(context);
},
onPurchased: () => showToast(
context: context,
message: translations.subscriptionPurchaseSuccessful,
),
onPressed: () {
RevenueCatUIHelper.showPaywallIfNecessary(
requiresSubscriptionCallback: () async {
await showSettingsDialog(context);
},
onPurchased: () => showToast(
context: context,
message: translations.subscriptionPurchaseSuccessful,
),
onRestored: () => showToast(
context: context,
message: translations.subscriptionPurchaseRestored,
),
onError: () => showToast(
context: context,
message: translations.subscriptionPurchaseFailed,
isError: true,
onRestored: () => showToast(
context: context,
message: translations.subscriptionPurchaseRestored,
),
onError: () => showToast(
context: context,
message: translations.subscriptionPurchaseFailed,
isError: true,
),
);
},
),
const HorizontalSpacing.large(),
IconButton(
color: AppColors.primarySwatch,
icon: Icon(
Iconsax.arrow_left_2_outline,
size: Theme.of(context).appBarTheme.iconTheme!.size,
),
onPressed: () {
context.read<GraphBloc>().add(
GraphEvent.targetDateChanged(
date: state.targetDate.date.previousYear.add(
const Duration(days: 3),
),
),
);
},
),
},
),
const HorizontalSpacing.large(),
IconButton(
color: AppColors.primarySwatch,
icon: Icon(
Iconsax.arrow_right_3_outline,
size: Theme.of(context).appBarTheme.iconTheme!.size,
),
onPressed: nextButtonDisabled
? null
: () {
context.read<GraphBloc>().add(
GraphEvent.targetDateChanged(
date: state.targetDate.date.nextYear.add(
const Duration(days: 3),
),
),
);
},
),
),
],
),
],
);
},
);
}
}
Loading

0 comments on commit e606d1e

Please sign in to comment.