6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 017b0075

AuthorNKL<nikolaj.king@gmail.com>
Date2024-11-22 11:40:32 +0100
clean profile settings code a bit

Changed files

comwell_key_app/lib/home/home_page.dart            |  6 +-
 comwell_key_app/lib/key/key_page.dart              |  1 -
 .../lib/key/repository/key_repository.dart         |  5 +-
 .../lib/overview/cubit/overview_cubit.dart         |  6 --
 .../components/change_password_modal.dart          | 10 ++--
 .../components/comwell_text_field.dart             |  6 +-
 .../components/date_time_picker.dart               |  2 +-
 .../components/intl_phone_field.dart               |  6 +-
 .../profile_settings/profile_settings_page.dart    | 67 +++++++++++++---------
 .../profile_settings_repository.dart               | 13 +----
 comwell_key_app/lib/routing/app_router.dart        | 20 ++-----
 comwell_key_app/lib/services/api.dart              |  6 +-
 .../interceptors/response_handle_interceptor.dart  |  2 +-
 13 files changed, 69 insertions(+), 81 deletions(-)

Diff

diff --git a/comwell_key_app/lib/home/home_page.dart b/comwell_key_app/lib/home/home_page.dart
index 7c852231..373cc5b8 100644
--- a/comwell_key_app/lib/home/home_page.dart
+++ b/comwell_key_app/lib/home/home_page.dart
@@ -40,7 +40,7 @@ class _HomeWidget extends State<HomeWidget> {
context.read<HomeBloc>().add(const ProvisionKeyEvent("Hotel123"));
}
if (state == const HomeState.keyProvisioned()) {
- context.read<HomeBloc>().add(SearchForKeysEvent());
+ context.read<HomeBloc>().add(const SearchForKeysEvent());
}
},
@@ -74,10 +74,10 @@ class _HomeWidget extends State<HomeWidget> {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: ElevatedButton(onPressed: () {
- context.read<HomeBloc>().add(SearchForKeysEvent(endpointNeedsUpdate: true));
+ context.read<HomeBloc>().add(const SearchForKeysEvent(endpointNeedsUpdate: true));
}
- , child: Text('Get Key')),
+ , child: const Text('Get Key')),
),
if(state.status == HomeStatus.validKey || state.status == HomeStatus.multipleKeys)
Padding(
diff --git a/comwell_key_app/lib/key/key_page.dart b/comwell_key_app/lib/key/key_page.dart
index 12f5bd3c..db4e9e54 100644
--- a/comwell_key_app/lib/key/key_page.dart
+++ b/comwell_key_app/lib/key/key_page.dart
@@ -1,6 +1,5 @@
import 'package:comwell_key_app/components/round_icon_button.dart';
import 'package:comwell_key_app/key/bloc/key_bloc.dart';
-import 'package:comwell_key_app/routing/app_routes.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
diff --git a/comwell_key_app/lib/key/repository/key_repository.dart b/comwell_key_app/lib/key/repository/key_repository.dart
index 7b24080c..71d715c2 100644
--- a/comwell_key_app/lib/key/repository/key_repository.dart
+++ b/comwell_key_app/lib/key/repository/key_repository.dart
@@ -1,5 +1,4 @@
import 'dart:io';
-
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:permission_handler/permission_handler.dart';
@@ -76,7 +75,9 @@ class KeyRepository {
1,
2,
]).then( (value) {
- print('startScanning: "scanned');
+ if (kDebugMode) {
+ print('startScanning: "scanned');
+ }
});
} catch (e) {
diff --git a/comwell_key_app/lib/overview/cubit/overview_cubit.dart b/comwell_key_app/lib/overview/cubit/overview_cubit.dart
index 0ae60145..810d83af 100644
--- a/comwell_key_app/lib/overview/cubit/overview_cubit.dart
+++ b/comwell_key_app/lib/overview/cubit/overview_cubit.dart
@@ -19,10 +19,4 @@ class OverviewCubit extends Cubit<OverviewState> {
emit(OverviewError(error: e.toString()));
}
}
-
-
- @override
- Future<void> close() {
- return super.close();
- }
}
diff --git a/comwell_key_app/lib/profile_settings/components/change_password_modal.dart b/comwell_key_app/lib/profile_settings/components/change_password_modal.dart
index 86ef1071..d1da8db4 100644
--- a/comwell_key_app/lib/profile_settings/components/change_password_modal.dart
+++ b/comwell_key_app/lib/profile_settings/components/change_password_modal.dart
@@ -2,18 +2,20 @@ import 'package:comwell_key_app/components/bottom_sheet_widget.dart';
import 'package:flutter/material.dart';
class ChangePasswordModal extends StatefulWidget {
+ const ChangePasswordModal({super.key});
+
@override
- _ChangePasswordModalState createState() => _ChangePasswordModalState();
+ ChangePasswordModalState createState() => ChangePasswordModalState();
}
-class _ChangePasswordModalState extends State<ChangePasswordModal> {
+class ChangePasswordModalState extends State<ChangePasswordModal> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
- title: Text('Change Password'),
+ title: const Text('Change Password'),
),
- body: BottomSheetWidget(widgetChildren: [const Text("data")],)
+ body: const BottomSheetWidget(widgetChildren: [Text("data")],)
);
}
}
\ No newline at end of file
diff --git a/comwell_key_app/lib/profile_settings/components/comwell_text_field.dart b/comwell_key_app/lib/profile_settings/components/comwell_text_field.dart
index cc0624ab..71bfeb7e 100644
--- a/comwell_key_app/lib/profile_settings/components/comwell_text_field.dart
+++ b/comwell_key_app/lib/profile_settings/components/comwell_text_field.dart
@@ -7,7 +7,7 @@ class ComwellTextField extends StatefulWidget {
final bool readOnly;
final TextEditingController controller;
- ComwellTextField({
+ const ComwellTextField({
super.key,
required this.fieldName,
required this.initialValue,
@@ -15,10 +15,10 @@ class ComwellTextField extends StatefulWidget {
required this.controller,
});
@override
- _ComwellTextFieldState createState() => _ComwellTextFieldState();
+ ComwellTextFieldState createState() => ComwellTextFieldState();
}
-class _ComwellTextFieldState extends State<ComwellTextField> {
+class ComwellTextFieldState extends State<ComwellTextField> {
late FocusNode _focusNode;
bool _isFocused = false;
diff --git a/comwell_key_app/lib/profile_settings/components/date_time_picker.dart b/comwell_key_app/lib/profile_settings/components/date_time_picker.dart
index 5bd4a499..96433edc 100644
--- a/comwell_key_app/lib/profile_settings/components/date_time_picker.dart
+++ b/comwell_key_app/lib/profile_settings/components/date_time_picker.dart
@@ -16,7 +16,7 @@ class DateTimePicker extends StatefulWidget {
class _DatePickerState extends State<DateTimePicker> {
DateTime? _selectedDate;
- Future _selectDate(BuildContext context) async => showDatePicker(
+ Future<void> _selectDate(BuildContext context) async => showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2000),
diff --git a/comwell_key_app/lib/profile_settings/components/intl_phone_field.dart b/comwell_key_app/lib/profile_settings/components/intl_phone_field.dart
index a32755df..65da9bef 100644
--- a/comwell_key_app/lib/profile_settings/components/intl_phone_field.dart
+++ b/comwell_key_app/lib/profile_settings/components/intl_phone_field.dart
@@ -1,7 +1,7 @@
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:country_code_picker/country_code_picker.dart';
import 'package:flutter/material.dart';
-import 'package:flutter/widgets.dart';
+
class IntlPhoneField extends StatefulWidget {
final String title;
@@ -10,10 +10,10 @@ class IntlPhoneField extends StatefulWidget {
{required this.title, required this.phoneNumber, super.key});
@override
- _IntlPhoneFieldState createState() => _IntlPhoneFieldState();
+ IntlPhoneFieldState createState() => IntlPhoneFieldState();
}
-class _IntlPhoneFieldState extends State<IntlPhoneField> {
+class IntlPhoneFieldState extends State<IntlPhoneField> {
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
@override
diff --git a/comwell_key_app/lib/profile_settings/profile_settings_page.dart b/comwell_key_app/lib/profile_settings/profile_settings_page.dart
index 03d86b97..3ed1a8ac 100644
--- a/comwell_key_app/lib/profile_settings/profile_settings_page.dart
+++ b/comwell_key_app/lib/profile_settings/profile_settings_page.dart
@@ -1,5 +1,5 @@
import 'package:comwell_key_app/components/comwell_app_bar.dart';
-import 'package:comwell_key_app/profile_settings/components/Text_field_trailing_icon.dart';
+import 'package:comwell_key_app/profile_settings/components/text_field_trailing_icon.dart';
import 'package:comwell_key_app/profile_settings/components/address_bottom_sheet.dart';
import 'package:comwell_key_app/profile_settings/components/comwell_text_field.dart';
import 'package:comwell_key_app/profile_settings/components/date_time_picker.dart';
@@ -19,7 +19,6 @@ class ProfileSettingsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
- final TextEditingController controller = TextEditingController();
context.read<ProfileSettingsCubit>().fetchProfileSettings();
return BlocBuilder<ProfileSettingsCubit, ProfileSettingsState>(
builder: (context, state) {
@@ -118,32 +117,7 @@ class ProfileSettingsPage extends StatelessWidget {
onTap: () {},
showTitle: false),
const SizedBox(height: 40),
- Center(
- child: OutlinedButton(
- onPressed: () {},
- style: OutlinedButton.styleFrom(
- side: const BorderSide(color: colorDivider),
- backgroundColor: Colors.transparent,
- shape: const RoundedRectangleBorder(
- borderRadius: BorderRadius.all(Radius.circular(20)),
- ),
- minimumSize: const Size(135, 40),
- maximumSize: const Size(155, 40),
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- SvgPicture.asset("assets/icons/trash-can.svg",
- height: 16),
- const SizedBox(width: 4),
- Text(
- "delete_profile".tr(),
- style: theme.textTheme.labelLarge
- ?.copyWith(color: Colors.red),
- ),
- ]),
- ),
- ),
+ const DeleteProfileButton(),
],
),
),
@@ -152,3 +126,40 @@ class ProfileSettingsPage extends StatelessWidget {
);
}
}
+
+class DeleteProfileButton extends StatelessWidget {
+ const DeleteProfileButton({
+ super.key,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = Theme.of(context);
+ return Center(
+ child: OutlinedButton(
+ onPressed: () {},
+ style: OutlinedButton.styleFrom(
+ side: const BorderSide(color: colorDivider),
+ backgroundColor: Colors.transparent,
+ shape: const RoundedRectangleBorder(
+ borderRadius: BorderRadius.all(Radius.circular(20)),
+ ),
+ minimumSize: const Size(135, 40),
+ maximumSize: const Size(155, 40),
+ ),
+ child: Row(
+ mainAxisAlignment: MainAxisAlignment.start,
+ children: [
+ SvgPicture.asset("assets/icons/trash-can.svg",
+ height: 16),
+ const SizedBox(width: 4),
+ Text(
+ "delete_profile".tr(),
+ style: theme.textTheme.labelLarge
+ ?.copyWith(color: Colors.red),
+ ),
+ ]),
+ ),
+ );
+ }
+}
diff --git a/comwell_key_app/lib/profile_settings/profile_settings_repository.dart b/comwell_key_app/lib/profile_settings/profile_settings_repository.dart
index 986d47f8..4452e886 100644
--- a/comwell_key_app/lib/profile_settings/profile_settings_repository.dart
+++ b/comwell_key_app/lib/profile_settings/profile_settings_repository.dart
@@ -1,12 +1,9 @@
-import 'package:comwell_key_app/profile_settings/model/address.dart';
import 'package:comwell_key_app/profile_settings/model/user.dart';
import 'package:comwell_key_app/services/api.dart';
-import 'package:shared_preferences/shared_preferences.dart';
import 'dart:convert';
class ProfileSettingsRepository {
final Api api = Api();
-
Future<User?> fetchProfileSettings() async {
final userJson = await api.fetchProfileSettings();
@@ -14,11 +11,7 @@ class ProfileSettingsRepository {
return User.fromJson(jsonDecode(userJson as String));
}
return null;
-}
-
-
-
- Future<void> updateUser(User updatedUser) async {
-
}
- }
\ No newline at end of file
+
+ Future<void> updateUser(User updatedUser) async {}
+}
diff --git a/comwell_key_app/lib/routing/app_router.dart b/comwell_key_app/lib/routing/app_router.dart
index eb76e07b..b353cbf1 100644
--- a/comwell_key_app/lib/routing/app_router.dart
+++ b/comwell_key_app/lib/routing/app_router.dart
@@ -20,7 +20,7 @@ final _rootNavigatorKey = GlobalKey<NavigatorState>();
GoRouter goRouter(AuthenticationBloc authBloc) {
return GoRouter(
- initialLocation: '/profilesettings',
+ initialLocation: '/oauthredirect',
navigatorKey: _rootNavigatorKey,
debugLogDiagnostics: true,
refreshListenable:
@@ -50,18 +50,6 @@ GoRouter goRouter(AuthenticationBloc authBloc) {
return null;
},
routes: <GoRoute>[
- GoRoute(
- path: "/profilesettings",
- name: AppRoutes.profileSettings.name,
- builder: (context, state) => const ProfileSettingsPage(),
- routes: [
- GoRoute(
- path: 'change_password',
- name: AppRoutes.changePassword.name,
- builder: (context, state) {
- return ChangePasswordModal();
- })
- ]),
GoRoute(
path: "/oauthredirect",
name: AppRoutes.overview.name,
@@ -74,7 +62,7 @@ GoRouter goRouter(AuthenticationBloc authBloc) {
return ProfilePage(); //mobileKey: key);
},
routes: [
- /* GoRoute(
+ GoRoute(
path: "profilesettings",
name: AppRoutes.profileSettings.name,
builder: (context, state) => const ProfileSettingsPage(),
@@ -83,9 +71,9 @@ GoRouter goRouter(AuthenticationBloc authBloc) {
path: 'change_password',
name: AppRoutes.changePassword.name,
builder: (context, state) {
- return ChangePasswordModal();
+ return const ChangePasswordModal();
})
- ]), */
+ ]),
],
),
GoRoute(
diff --git a/comwell_key_app/lib/services/api.dart b/comwell_key_app/lib/services/api.dart
index 179baa54..41efcc52 100644
--- a/comwell_key_app/lib/services/api.dart
+++ b/comwell_key_app/lib/services/api.dart
@@ -13,11 +13,11 @@ class Api {
}
}
- Future<dynamic> logout() async {
+ Future<Response<dynamic>> logout() async {
return await dio.post('/logout');
}
- Future<dynamic> fetchAllBookingsForUser(String userId) async {
+ Future<Response<dynamic>> fetchAllBookingsForUser(String userId) async {
return await dio.get('/booking/v1/GetCurrentBookingsFunction/$userId');
}
@@ -31,7 +31,7 @@ class Api {
}
Future<dynamic> fetchProfileSettings() async {
- await Future.delayed(const Duration(seconds: 2));
+ await Future<void>.delayed(const Duration(seconds: 2));
// Return the mock JSON data
return '''
diff --git a/comwell_key_app/lib/services/interceptors/response_handle_interceptor.dart b/comwell_key_app/lib/services/interceptors/response_handle_interceptor.dart
index 08a5c54f..c6a96008 100644
--- a/comwell_key_app/lib/services/interceptors/response_handle_interceptor.dart
+++ b/comwell_key_app/lib/services/interceptors/response_handle_interceptor.dart
@@ -85,7 +85,7 @@ class ResponseHandleInterceptor extends Interceptor {
final Dio refreshDio = Dio(BaseOptions(
baseUrl:
'https://comwellservicesdev.b2clogin.com/comwellservicesdev.onmicrosoft.com/oauth2/v2.0/token?p=b2c_1a_signin'));
- final response = await refreshDio.post(
+ final response = await refreshDio.post<dynamic>(
'',
data: {'refreshToken': refreshToken},
);