6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit e4eb10ea

AuthorEdmir Suljic<esu@dwarf.dk>
Date2026-03-05 15:01:43 +0100
db bug and other prereg bugs

Changed files

comwell_key_app/lib/database/comwell_db.dart       | 45 ++++++----
 .../components/check_in_button_timer.dart          |  2 +-
 .../pregistration/cubit/preregistration_cubit.dart |  4 +-
 .../pages/prereg_confirmation_page.dart            | 96 ++++++++++++++--------
 .../profile_settings/profile_settings_screen.dart  |  5 +-
 5 files changed, 96 insertions(+), 56 deletions(-)

Diff

diff --git a/comwell_key_app/lib/database/comwell_db.dart b/comwell_key_app/lib/database/comwell_db.dart
index af68b22e..57de17df 100644
--- a/comwell_key_app/lib/database/comwell_db.dart
+++ b/comwell_key_app/lib/database/comwell_db.dart
@@ -96,29 +96,40 @@ class ComwellDatabase extends _$ComwellDatabase {
final file = File(p.join(path.path, _dbFileName));
final cipher = await getCipher();
- void setup(Database db) {
+ // Pre-validate the existing database file with SQLCipher. If it is not a
+ // valid SQLCipher database (typical when migrating from an unencrypted
+ // DB), delete it so Drift can recreate a fresh one.
+ if (await file.exists()) {
try {
- final result = db.select("pragma cipher_version");
- if (result.isEmpty) {
- throw UnsupportedError(
- "This database needs to run with SQLCipher, but that library is unavailable");
+ final db = sqlite3.open(file.path);
+ try {
+ db.execute('pragma key = \"$cipher\"');
+ db.execute('select count(*) from sqlite_master');
+ } finally {
+ db.dispose();
+ }
+ } on SqliteException catch (e) {
+ if (e.message.contains("file is not a database")) {
+ await file.delete();
+ } else {
+ rethrow;
}
- db.execute("pragma key = \"$cipher\"");
- db.execute("select count(*) from sqlite_master");
- // Add pragmas for better stability
- db.execute("pragma journal_mode = WAL");
- db.execute("pragma synchronous = NORMAL");
- db.execute("pragma cache_size = 1000");
- db.execute("pragma temp_store = MEMORY");
- } catch (e) {
- // If setup fails, the database might be corrupted
- // The error will be caught by the calling code
- rethrow;
}
}
+ void setup(Database db) {
+ // Apply the encryption key for all connections created by Drift.
+ db.execute('pragma key = \"$cipher\"');
+
+ // Optional pragmas for stability / performance.
+ db.execute("pragma journal_mode = WAL");
+ db.execute("pragma synchronous = NORMAL");
+ db.execute("pragma cache_size = 1000");
+ db.execute("pragma temp_store = MEMORY");
+ }
+
// Use synchronous database creation instead of createInBackground
- // to avoid isolate channel issues during concurrent access
+ // to avoid isolate channel issues during concurrent access.
return NativeDatabase(file, setup: setup);
});
}
diff --git a/comwell_key_app/lib/presentation/screens/booking_details/components/check_in_button_timer.dart b/comwell_key_app/lib/presentation/screens/booking_details/components/check_in_button_timer.dart
index 7a9a421e..6f2af8ae 100644
--- a/comwell_key_app/lib/presentation/screens/booking_details/components/check_in_button_timer.dart
+++ b/comwell_key_app/lib/presentation/screens/booking_details/components/check_in_button_timer.dart
@@ -140,7 +140,7 @@ class _CheckInButtonTimerState extends State<CheckInButtonTimer> {
],
),
),
- if (!hasAddons && availableUpSales != null) ...[
+ if (availableUpSales != null) ...[
Divider(color: colorBackground.withValues(alpha: 0.1)),
GestureDetector(
onTap: widget.buyEarlyCheckin,
diff --git a/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart b/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart
index 2b9bb384..fa3517d7 100644
--- a/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart
+++ b/comwell_key_app/lib/presentation/screens/pregistration/cubit/preregistration_cubit.dart
@@ -71,8 +71,8 @@ class PreregistrationCubit extends BaseCubit<PreregistrationState> {
postalCodeTextController.text = user.address.zipCode;
cityTextController.text = user.address.city;
- selectedNationality = user.nationality;
- selectedCountry = user.nationality;
+ selectedNationality = user.nationality != '' ? user.nationality : 'DK';
+ selectedCountry = user.nationality != '' ? user.nationality : 'DK';
countryCode = getCountryCodeFromPhoneNumber(user.phoneNumber).$1;
phoneNumber = getCountryCodeFromPhoneNumber(user.phoneNumber).$2;
diff --git a/comwell_key_app/lib/presentation/screens/pregistration/pages/prereg_confirmation_page.dart b/comwell_key_app/lib/presentation/screens/pregistration/pages/prereg_confirmation_page.dart
index ec1acc62..18229ead 100644
--- a/comwell_key_app/lib/presentation/screens/pregistration/pages/prereg_confirmation_page.dart
+++ b/comwell_key_app/lib/presentation/screens/pregistration/pages/prereg_confirmation_page.dart
@@ -4,6 +4,7 @@ import 'package:comwell_key_app/presentation/screens/pregistration/cubit/preregi
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
import 'package:comwell_key_app/utils/urls.dart';
+import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:url_launcher/url_launcher.dart';
@@ -33,10 +34,13 @@ class PreregConfirmationPage extends StatelessWidget {
);
}
- return SafeArea(
- child: ListView(
- padding: const EdgeInsets.symmetric(horizontal: 12.0),
- children: [
+ return GestureDetector(
+ onTap: () => FocusScope.of(context).unfocus(),
+ behavior: HitTestBehavior.translucent,
+ child: SafeArea(
+ child: ListView(
+ padding: const EdgeInsets.symmetric(horizontal: 12.0),
+ children: [
const SizedBox(height: 16),
Text(
context.strings.preregistration_confirmation_title,
@@ -131,41 +135,64 @@ class PreregConfirmationPage extends StatelessWidget {
),
),
const SizedBox(height: 12),
- // Serving time fieldƒ
+ // Serving time field
GestureDetector(
onTap: () async {
- final time = await showTimePicker(
- builder: (context, child) {
- return Theme(
- data: theme.copyWith(
- timePickerTheme: TimePickerThemeData(
- hourMinuteColor: sandColor,
- hourMinuteTextColor: Colors.white,
- dialHandColor: sandColor,
- dialBackgroundColor: sandColor[10],
- entryModeIconColor: sandColor,
- ),
- textButtonTheme: TextButtonThemeData(
- style: TextButton.styleFrom(
- foregroundColor: sandColor,
- textStyle: theme.textTheme.labelLarge,
+ final initialTimeOfDay = state.servingTime ?? TimeOfDay.now();
+ final initialDateTime = DateTime(
+ 0,
+ 1,
+ 1,
+ initialTimeOfDay.hour,
+ initialTimeOfDay.minute,
+ );
+
+ final selectedTime = await showModalBottomSheet<TimeOfDay>(
+ context: context,
+ builder: (context) {
+ DateTime tempPicked = initialDateTime;
+
+ return SizedBox(
+ height: 260,
+ child: Column(
+ children: [
+ Align(
+ alignment: Alignment.centerRight,
+ child: TextButton(
+ onPressed: () {
+ Navigator.of(context).pop(
+ TimeOfDay(
+ hour: tempPicked.hour,
+ minute: tempPicked.minute,
+ ),
+ );
+ },
+ child: Text(
+ MaterialLocalizations.of(context).okButtonLabel,
+ style: theme.textTheme.labelLarge?.copyWith(
+ color: sandColor,
+ ),
+ ),
+ ),
),
- ),
- ),
- child: MediaQuery(
- data: MediaQuery.of(context).copyWith(
- alwaysUse24HourFormat: true,
- ),
- child: child!,
+ Expanded(
+ child: CupertinoDatePicker(
+ mode: CupertinoDatePickerMode.time,
+ use24hFormat: true,
+ initialDateTime: initialDateTime,
+ onDateTimeChanged: (DateTime newDate) {
+ tempPicked = newDate;
+ },
+ ),
+ ),
+ ],
),
);
},
- context: context,
- initialTime: state.servingTime ?? TimeOfDay.now(),
- initialEntryMode: TimePickerEntryMode.inputOnly,
);
- if (time != null) {
- cubit.onServingTimeSelected(time);
+
+ if (selectedTime != null) {
+ cubit.onServingTimeSelected(selectedTime);
}
},
child: Container(
@@ -299,8 +326,9 @@ class PreregConfirmationPage extends StatelessWidget {
),
],
),
- const SizedBox(height: 40),
- ],
+ const SizedBox(height: 40),
+ ],
+ ),
),
);
},
diff --git a/comwell_key_app/lib/presentation/screens/profile_settings/profile_settings_screen.dart b/comwell_key_app/lib/presentation/screens/profile_settings/profile_settings_screen.dart
index 5555f393..bcabaacb 100644
--- a/comwell_key_app/lib/presentation/screens/profile_settings/profile_settings_screen.dart
+++ b/comwell_key_app/lib/presentation/screens/profile_settings/profile_settings_screen.dart
@@ -3,6 +3,7 @@ import 'package:comwell_key_app/common/components/comwell_app_bar.dart';
import 'package:comwell_key_app/common/components/shimmer_loader/profile_settings_shimmer_loader.dart';
import 'package:comwell_key_app/domain/models/user.dart';
import 'package:comwell_key_app/presentation/app/bloc/profile_cubit.dart';
+import 'package:country_code_picker/country_code_picker.dart';
import 'components/address_bottom_sheet.dart';
import 'components/comwell_text_field.dart';
import 'components/date_time_picker.dart';
@@ -104,8 +105,8 @@ class ProfileSettingsScreen extends StatelessWidget {
const SizedBox(height: 8),
IntlPhoneField(
title: context.strings.profile_settings_phone,
- phoneNumber: cubit.phoneNumber!,
- countryCode: cubit.countryCode!,
+ phoneNumber: cubit.phoneNumber ?? '',
+ countryCode: cubit.countryCode ?? CountryCode.fromCountryCode('DK'),
controller: cubit.phoneNumberController,
readOnly: false,
onSubmitted: (value) {