Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,23 @@ class ProfileSubscriptionSectionWidget extends StatefulWidget {
class _ProfileSubscriptionSectionWidgetState extends State<ProfileSubscriptionSectionWidget> {
bool _isCancelDialogOpen = false;

void _openCatalog() {
unawaited(context.push(AppRoutePaths.subscriptionsCatalogPath));
Future<void> _openCatalog() async {
final didPurchase = await context.push<bool>(AppRoutePaths.subscriptionsCatalogPath);
if (!mounted) return;
if (didPurchase == true) {
unawaited(context.read<ProfileSubscriptionCubit>().load());
}
}

Future<void> _openSubscriptionDetails(SubscriptionCatalogItem item) async {
final didPurchase = await context.push<bool>(
AppRoutePaths.subscriptionsDetailsConcretePath(item.id),
extra: item,
);
if (!mounted) return;
if (didPurchase == true) {
unawaited(context.read<ProfileSubscriptionCubit>().load());
}
}

void _showCancelDialog() {
Expand Down Expand Up @@ -131,14 +146,16 @@ class _ProfileSubscriptionSectionWidgetState extends State<ProfileSubscriptionSe
);
}

final item = state.item;
return _ProfileSubscriptionActiveState(
activeSubscription: activeSubscription,
item: state.item,
item: item,
isCardLoading: state.isLoading,
hasCardFailure: state.failure != null,
onRetryPressed: () => context.read<ProfileSubscriptionCubit>().retry(),
onRenewPressed: _openCatalog,
onCancelPressed: _showCancelDialog,
onSubscriptionCardPressed: item == null ? null : () => _openSubscriptionDetails(item),
);
},
),
Expand All @@ -154,6 +171,7 @@ final class _ProfileSubscriptionActiveState extends StatelessWidget {
final VoidCallback onRetryPressed;
final VoidCallback onRenewPressed;
final VoidCallback onCancelPressed;
final VoidCallback? onSubscriptionCardPressed;

const _ProfileSubscriptionActiveState({
required this.activeSubscription,
Expand All @@ -163,6 +181,7 @@ final class _ProfileSubscriptionActiveState extends StatelessWidget {
required this.onRetryPressed,
required this.onRenewPressed,
required this.onCancelPressed,
required this.onSubscriptionCardPressed,
});

@override
Expand Down Expand Up @@ -202,7 +221,7 @@ final class _ProfileSubscriptionActiveState extends StatelessWidget {
if (item != null)
SubscriptionCard(
item: item!,
onPressed: () => context.push(AppRoutePaths.subscriptionsDetailsConcretePath(item!.id)),
onPressed: onSubscriptionCardPressed,
)
else if (isCardLoading)
const _ProfileSubscriptionCardLoadingState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,14 @@ class SubscriptionsCatalogPage extends StatelessWidget {
final item = items[index];
final onPressed = item.id <= 0
? null
: () => context.push(
AppRoutePaths.subscriptionsDetailsConcretePath(item.id),
extra: item,
);
: () async {
final didPurchase = await context.push<bool>(
AppRoutePaths.subscriptionsDetailsConcretePath(item.id),
extra: item,
);
if (!context.mounted || didPurchase != true) return;
context.pop(true);
};
return Padding(
padding: EdgeInsets.only(bottom: index == items.length - 1 ? 0 : 12),
child: SubscriptionCard(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -48,7 +46,7 @@ class SubscriptionsDetailsPage extends StatelessWidget {
paymentCubit: context.read<SubscriptionPaymentCubit>(),
);
if (!context.mounted || didPay != true) return;
context.go(AppRoutePaths.profilePath);
context.pop(true);
}

@override
Expand Down
Loading