import 'package:comwell_key_app/common/components/comwell_app_bar.dart';
import 'package:comwell_key_app/presentation/screens/pregistration/cubit/preregistration_state.dart';
import 'package:comwell_key_app/presentation/screens/pregistration/cubit/preregistration_cubit.dart';
import 'package:comwell_key_app/presentation/screens/pregistration/utils/utils.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:comwell_key_app/common/components/shimmer_loader/prereg_flow_shimmer_loader.dart';
class PreregistrationFlow extends StatefulWidget {
const PreregistrationFlow({super.key});
@override
State<PreregistrationFlow> createState() => _PreregistrationFlowState();
}
class _PreregistrationFlowState extends State<PreregistrationFlow> {
@override
Widget build(BuildContext context) {
return BlocBuilder<PreregistrationCubit, PreregistrationState>(
builder: (context, state) {
final cubit = context.read<PreregistrationCubit>();
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
appBar: ComwellAppBar(
shouldShowProfileButton: false,
shouldShowBackButton: true,
onBackPressed: () {
if (cubit.currentPage == PreregistrationPage.profile) {
context.pop();
} else {
cubit.onBackClicked();
}
},
),
body: Builder(
builder: (context) {
if (state.isLoading) {
return const Center(child: PreregFlowShimmerLoader());
}
return PageView(
key: const PageStorageKey("prereg_flow"),
physics: const NeverScrollableScrollPhysics(),
controller: cubit.pageController,
children: PreregistrationPage.getPages(ValueKey(state)).toList(),
);
},
),
bottomNavigationBar: Builder(
builder: (context) {
if (state.isLoading) return const SizedBox();
return Column(
// BOTTOM NAVIGATION
mainAxisSize: MainAxisSize.min,
children: [
const Divider(
color: Colors.black12,
height: 0,
),
Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 40.0),
child: ElevatedButton(
onPressed: cubit.canContinue
? () {
cubit.onContinueClicked(context);
}
: null,
style: ElevatedButton.styleFrom(foregroundColor: colorBackground),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Text(cubit.buttonText(context)),
),
),
),
),
],
),
],
);
},
),
);
},
);
}
}