Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add logout on get started page #61

Merged
merged 1 commit into from
Oct 13, 2024
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
43 changes: 17 additions & 26 deletions app/lib/pages/get_started/page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:auto_route/auto_route.dart';
import 'package:chuckle_chest/app/router.dart';
import 'package:chuckle_chest/localization/l10n.dart';
import 'package:chuckle_chest/pages/get_started/widgets/_widgets.dart';
import 'package:chuckle_chest/shared/_shared.dart';
import 'package:chuckle_chest/shared/dialogs/_dialogs.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

Expand Down Expand Up @@ -33,6 +33,9 @@ class CGetStartedPage extends StatelessWidget implements AutoRouteWrapper {
create: (context) =>
CChestCreationCubit(chestRepository: context.read()),
),
BlocProvider(
create: (context) => CSignoutCubit(authRepository: context.read()),
),
],
child: MultiBlocListener(
listeners: [
Expand All @@ -46,6 +49,16 @@ class CGetStartedPage extends StatelessWidget implements AutoRouteWrapper {
const CErrorSnackBar().show(context),
},
),
BlocListener<CSignoutCubit, CSignoutState>(
listener: (context, state) => switch (state.status) {
CRequestCubitStatus.initial => null,
CRequestCubitStatus.inProgress => null,
CRequestCubitStatus.succeeded =>
context.router.replace(const CSigninRoute()),
CRequestCubitStatus.failed =>
const CErrorSnackBar().show(context),
},
),
],
child: this,
),
Expand All @@ -58,33 +71,11 @@ class CGetStartedPage extends StatelessWidget implements AutoRouteWrapper {
appBar: CAppBar(
context: context,
title: Text(context.cAppL10n.getStartedPage_title),
actions: [
PopupMenuButton(
icon: const Icon(Icons.more_vert_rounded),
itemBuilder: (context) => [
PopupMenuItem(
value: 1,
child: Text(context.cAppL10n.getStartedPage_logoutButton),
),
],
),
],
actions: const [CGetStartedPageMoreMenu()],
),
body: ListView(
padding: const EdgeInsets.all(24),
children: [
CLoadingButton<CChestCreationCubit, CChestCreationState>(
child: Text(context.cAppL10n.getStartedPage_createChestButton),
isLoading: (state) =>
state.status == CRequestCubitStatus.inProgress,
onPressed: (context, cubit) =>
CChestCreationDialog(cubit: cubit).show(context),
builder: (context, text, onPressed) => FilledButton(
onPressed: onPressed,
child: text,
),
),
],
padding: const EdgeInsets.all(16),
children: const [CCreateChestButton()],
),
);
}
Expand Down
2 changes: 2 additions & 0 deletions app/lib/pages/get_started/widgets/_widgets.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'create_chest_button.dart';
export 'more_menu.dart';
27 changes: 27 additions & 0 deletions app/lib/pages/get_started/widgets/create_chest_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:chuckle_chest/localization/l10n.dart';
import 'package:chuckle_chest/shared/_shared.dart';
import 'package:chuckle_chest/shared/dialogs/_dialogs.dart';
import 'package:flutter/material.dart';

/// {@template CCreateChestButton}
///
/// The button on the get started page that allows the user to create a new
/// chest.
///
/// {@endtemplate}
class CCreateChestButton extends StatelessWidget {
/// {@macro CCreateChestButton}
const CCreateChestButton({super.key});

@override
Widget build(BuildContext context) {
return CLoadingButton<CChestCreationCubit, CChestCreationState>(
child: Text(context.cAppL10n.getStartedPage_createChestButton),
isLoading: (state) => state.status == CRequestCubitStatus.inProgress,
onPressed: (context, cubit) =>
CChestCreationDialog(cubit: cubit).show(context),
builder: (context, text, onPressed) =>
FilledButton(onPressed: onPressed, child: text),
);
}
}
37 changes: 37 additions & 0 deletions app/lib/pages/get_started/widgets/more_menu.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:chuckle_chest/localization/l10n.dart';
import 'package:chuckle_chest/shared/_shared.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

/// {@template CGetStartedPageMoreMenu}
///
/// The button on the app bar of the get started page that opens a menu with
/// additional options, such as signing out.
///
/// {@endtemplate}
class CGetStartedPageMoreMenu extends StatelessWidget {
/// {@macro CGetStartedPageMoreMenu}
const CGetStartedPageMoreMenu({super.key});

@override
Widget build(BuildContext context) {
return BlocBuilder<CSignoutCubit, CSignoutState>(
builder: (context, state) => PopupMenuButton(
icon: const Icon(Icons.more_vert_rounded),
itemBuilder: (context) => [
PopupMenuItem(
value: 1,
onTap: state.status != CRequestCubitStatus.inProgress
? () => context.read<CSignoutCubit>().signOut()
: null,
child: state.status != CRequestCubitStatus.inProgress
? Text(context.cAppL10n.getStartedPage_logoutButton)
: const Center(
child: CCradleLoadingIndicator(ballSize: 8),
),
),
],
),
);
}
}