6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit f3557d8f
Changed files
comwell_key_app/assets/translations/da-DK.json | 1 + comwell_key_app/assets/translations/en-US.json | 1 + .../pregistration/bloc/preregistration_cubit.dart | 38 ++++++++++++++++------ .../lib/pregistration/preregistration_flow.dart | 32 ++++++++++++++---- 4 files changed, 55 insertions(+), 17 deletions(-)
Diff
diff --git a/comwell_key_app/assets/translations/da-DK.json b/comwell_key_app/assets/translations/da-DK.json
index 760e7f0f..8b7b0e9f 100644
--- a/comwell_key_app/assets/translations/da-DK.json
+++ b/comwell_key_app/assets/translations/da-DK.json
@@ -1,6 +1,7 @@
{
"generic_continue": "Fortsæt",
"generic_information_required": "Dette felt er påkrævet",
+ "generic_confirm": "Bekræft",
"welcome_headline": "Velkommen hos Comwell Hotels",
"welcome_button": "Fortsæt",
"welcome_error": "Der er sket en fejl. Genstart app.",
diff --git a/comwell_key_app/assets/translations/en-US.json b/comwell_key_app/assets/translations/en-US.json
index 1f90689a..58e56ebc 100644
--- a/comwell_key_app/assets/translations/en-US.json
+++ b/comwell_key_app/assets/translations/en-US.json
@@ -1,6 +1,7 @@
{
"generic_continue": "Continue",
"generic_information_required": "This information is required",
+ "generic_confirm": "Confirm",
"welcome_headline": "Welcome at Comwell Hotels",
"welcome_button": "Continue",
"welcome_error": "An error occurred. Please try again later.",
diff --git a/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart b/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart
index 5887efdb..49d26a8f 100644
--- a/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart
+++ b/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart
@@ -1,5 +1,7 @@
import 'package:bloc/bloc.dart';
import 'package:comwell_key_app/pregistration/bloc/preregistration_state.dart';
+import 'package:comwell_key_app/pregistration/preregistration_flow.dart';
+import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import '../../profile_settings/repostiory/profile_settings_repository.dart';
@@ -12,6 +14,9 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
final postalCodeTextController = TextEditingController();
final cityTextController = TextEditingController();
final countryTextController = TextEditingController();
+
+ PreregistrationPage get currentPage =>
+ PreregistrationPage.fromIndex(pageController.page?.toInt() ?? 0);
bool _isAnimating = false;
PreregistrationCubit() : super(const PreregistrationState.initial());
@@ -45,17 +50,18 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
void onContinueClicked() {
if (_isAnimating) return;
- switch (pageController.page?.round()) {
- case 0:
+ String text = "generic_continue".tr();
+ switch (currentPage) {
+ case PreregistrationPage.information:
onInformationContinueClicked();
- break;
- case 1:
+ case PreregistrationPage.paymentMethod:
+ text = "generic_confirm".tr();
onPaymentMethodsContinueClicked();
- break;
- case 2:
- // on Confirm;
+ case PreregistrationPage.confirmation:
+ _onConfirmPressed();
break;
}
+ emit(state.copyWith(buttonText: text));
}
void onPaymentMethodsContinueClicked() {
@@ -63,7 +69,18 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
_navigateNextPage();
}
- void onEditProfileClicked() {}
+ void _onConfirmPressed() async {
+ final index = PreregistrationPage.information.index;
+ _isAnimating = true;
+ await pageController.animateToPage(index,
+ duration: const Duration(milliseconds: 500),
+ curve: Curves.fastOutSlowIn);
+ _isAnimating = false;
+ }
+
+ void onEditProfileClicked() {
+ // TODO
+ }
void onBackClicked() {
if (_isAnimating) return;
@@ -76,7 +93,8 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
void _navigateNextPage() async {
_isAnimating = true;
await pageController.nextPage(
- duration: const Duration(milliseconds: 500), curve: Curves.fastOutSlowIn);
+ duration: const Duration(milliseconds: 500),
+ curve: Curves.fastOutSlowIn);
_isAnimating = false;
}
@@ -102,7 +120,7 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
bool get isPostalCodeValid =>
postalCodeTextController.text.isNotEmpty &&
- postalCodeTextController.text.length <= 4;
+ postalCodeTextController.text.length <= 4;
bool get isCityValid => cityTextController.text.isNotEmpty;
diff --git a/comwell_key_app/lib/pregistration/preregistration_flow.dart b/comwell_key_app/lib/pregistration/preregistration_flow.dart
index eb4fae18..694a18a2 100644
--- a/comwell_key_app/lib/pregistration/preregistration_flow.dart
+++ b/comwell_key_app/lib/pregistration/preregistration_flow.dart
@@ -4,10 +4,32 @@ import 'package:comwell_key_app/pregistration/pages/prereg_confirmation_page.dar
import 'package:comwell_key_app/pregistration/pages/prereg_information_page.dart';
import 'package:comwell_key_app/pregistration/pages/prereg_payment_page.dart';
import 'package:comwell_key_app/themes/dark_theme.dart';
-import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
+enum PreregistrationPage {
+ information,
+ paymentMethod,
+ confirmation;
+
+ static PreregistrationPage fromIndex(int index) {
+ return PreregistrationPage.values[index];
+ }
+
+ static Iterable<Widget> getPages() {
+ return PreregistrationPage.values.map((page) {
+ switch (page) {
+ case PreregistrationPage.information:
+ return const PreregInformationPage();
+ case PreregistrationPage.paymentMethod:
+ return const PreregPaymentPage();
+ case PreregistrationPage.confirmation:
+ return const PreregConfirmationPage();
+ }
+ });
+ }
+}
+
class PreregistrationFlow extends StatefulWidget {
const PreregistrationFlow({super.key});
@@ -49,7 +71,7 @@ class _PreregistrationFlowState extends State<PreregistrationFlow> {
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: () {
- cubit.onInformationContinueClicked();
+ cubit.onContinueClicked();
},
style: const ButtonStyle(
backgroundColor:
@@ -78,11 +100,7 @@ class _PreregistrationFlowState extends State<PreregistrationFlow> {
return PageView(
physics: const NeverScrollableScrollPhysics(),
controller: cubit.pageController,
- children: const [
- PreregInformationPage(),
- PreregPaymentPage(),
- PreregConfirmationPage(),
- ],
+ children: PreregistrationPage.getPages().toList(),
);
},
),