feat: Implement client settings and profile management feature with sign-out functionality.

This commit is contained in:
Achintha Isuru
2026-01-21 19:37:34 -05:00
parent 7d5a40b7e3
commit eace8a66af
21 changed files with 536 additions and 15 deletions

View File

@@ -0,0 +1,31 @@
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../domain/usecases/sign_out_usecase.dart';
part 'client_settings_event.dart';
part 'client_settings_state.dart';
/// BLoC to manage client settings and profile state.
class ClientSettingsBloc
extends Bloc<ClientSettingsEvent, ClientSettingsState> {
final SignOutUseCase _signOutUseCase;
ClientSettingsBloc({required SignOutUseCase signOutUseCase})
: _signOutUseCase = signOutUseCase,
super(const ClientSettingsInitial()) {
on<ClientSettingsSignOutRequested>(_onSignOutRequested);
}
Future<void> _onSignOutRequested(
ClientSettingsSignOutRequested event,
Emitter<ClientSettingsState> emit,
) async {
emit(const ClientSettingsLoading());
try {
await _signOutUseCase();
emit(const ClientSettingsSignOutSuccess());
} catch (e) {
emit(ClientSettingsError(e.toString()));
}
}
}

View File

@@ -0,0 +1,12 @@
part of 'client_settings_bloc.dart';
abstract class ClientSettingsEvent extends Equatable {
const ClientSettingsEvent();
@override
List<Object?> get props => [];
}
class ClientSettingsSignOutRequested extends ClientSettingsEvent {
const ClientSettingsSignOutRequested();
}

View File

@@ -0,0 +1,29 @@
part of 'client_settings_bloc.dart';
abstract class ClientSettingsState extends Equatable {
const ClientSettingsState();
@override
List<Object?> get props => [];
}
class ClientSettingsInitial extends ClientSettingsState {
const ClientSettingsInitial();
}
class ClientSettingsLoading extends ClientSettingsState {
const ClientSettingsLoading();
}
class ClientSettingsSignOutSuccess extends ClientSettingsState {
const ClientSettingsSignOutSuccess();
}
class ClientSettingsError extends ClientSettingsState {
final String message;
const ClientSettingsError(this.message);
@override
List<Object?> get props => [message];
}

View File

@@ -0,0 +1,10 @@
import 'package:flutter_modular/flutter_modular.dart';
/// Extension on [IModularNavigator] to provide strongly-typed navigation
/// for the client settings feature.
extension ClientSettingsNavigator on IModularNavigator {
/// Navigates to the client settings page.
void pushClientSettings() {
pushNamed('/client/settings/');
}
}

View File

@@ -0,0 +1,214 @@
import 'package:core_localization/core_localization.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_modular/flutter_modular.dart';
import '../blocs/client_settings_bloc.dart';
/// Page for client settings and profile management.
class ClientSettingsPage extends StatelessWidget {
/// Creates a [ClientSettingsPage].
const ClientSettingsPage({super.key});
@override
Widget build(BuildContext context) {
final labels = t.client_settings.profile;
return BlocProvider<ClientSettingsBloc>(
create: (context) => Modular.get<ClientSettingsBloc>(),
child: BlocListener<ClientSettingsBloc, ClientSettingsState>(
listener: (context, state) {
if (state is ClientSettingsSignOutSuccess) {
Modular.to.navigate('/');
}
if (state is ClientSettingsError) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(state.message)));
}
},
child: Scaffold(
backgroundColor: UiColors.background,
body: CustomScrollView(
slivers: [
SliverAppBar(
backgroundColor: UiColors.primary,
expandedHeight: 200,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
background: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [UiColors.primary, Color(0xFF0047FF)],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
height: UiConstants.space5 * 2,
), // Adjust for SafeArea
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: UiColors.white.withValues(alpha: 0.24),
width: 4,
),
color: UiColors.white,
),
child: const Center(
child: Text(
'C',
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
color: UiColors.primary,
),
),
),
),
const SizedBox(height: UiConstants.space3),
Text(
'Your Company',
style: UiTypography.body1b.copyWith(
color: UiColors.white,
),
),
const SizedBox(height: UiConstants.space1),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
UiIcons.mail,
size: 14,
color: UiColors.white.withValues(alpha: 0.7),
),
const SizedBox(width: UiConstants.space2),
Text(
'client@example.com',
style: UiTypography.footnote1r.copyWith(
color: UiColors.white.withValues(alpha: 0.7),
),
),
],
),
],
),
),
),
leading: IconButton(
icon: const Icon(UiIcons.arrowLeft, color: UiColors.white),
onPressed: () => Modular.to.pop(),
),
title: Text(
labels.title,
style: UiTypography.body1b.copyWith(color: UiColors.white),
),
),
SliverPadding(
padding: const EdgeInsets.all(UiConstants.space5),
sliver: SliverList(
delegate: SliverChildListDelegate([
UiButton.primary(
text: labels.edit_profile,
onPressed: () {},
),
const SizedBox(height: UiConstants.space4),
UiButton.primary(text: labels.hubs, onPressed: () {}),
const SizedBox(height: UiConstants.space4),
BlocBuilder<ClientSettingsBloc, ClientSettingsState>(
builder: (context, state) {
return UiButton.secondary(
text: labels.log_out,
onPressed: state is ClientSettingsLoading
? null
: () => BlocProvider.of<ClientSettingsBloc>(
context,
).add(const ClientSettingsSignOutRequested()),
);
},
),
const SizedBox(height: UiConstants.space5),
Card(
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: UiConstants.radiusLg,
side: const BorderSide(color: UiColors.border),
),
color: UiColors.white,
child: Padding(
padding: const EdgeInsets.all(UiConstants.space4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
labels.quick_links,
style: UiTypography.footnote1b.textPrimary,
),
const SizedBox(height: UiConstants.space3),
_buildQuickLink(
context,
icon: UiIcons.nfc,
title: labels.clock_in_hubs,
onTap: () {},
),
_buildQuickLink(
context,
icon: UiIcons.building,
title: labels.billing_payments,
onTap: () {},
),
],
),
),
),
]),
),
),
],
),
),
),
);
}
Widget _buildQuickLink(
BuildContext context, {
required IconData icon,
required String title,
required VoidCallback onTap,
}) {
return InkWell(
onTap: onTap,
borderRadius: UiConstants.radiusMd,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: UiConstants.space3,
horizontal: UiConstants.space2,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(icon, size: 20, color: UiColors.iconSecondary),
const SizedBox(width: UiConstants.space3),
Text(title, style: UiTypography.footnote1m.textPrimary),
],
),
const Icon(
UiIcons.chevronRight,
size: 20,
color: UiColors.iconThird,
),
],
),
),
);
}
}