feat: Refactor PhoneInput to use StatefulWidget and improve phone number handling

This commit is contained in:
Achintha Isuru
2026-02-01 21:45:40 -05:00
parent 3489ae4060
commit 6d0d7dcbd2
5 changed files with 32 additions and 22 deletions

View File

@@ -1,15 +1,15 @@
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_modular/flutter_modular.dart'; import 'package:flutter_modular/flutter_modular.dart';
import 'package:design_system/design_system.dart'; import 'package:staff_authentication/src/presentation/blocs/auth_bloc.dart';
import 'package:staff_authentication/src/domain/ui_entities/auth_mode.dart';
import 'package:staff_authentication/src/presentation/blocs/auth_event.dart'; import 'package:staff_authentication/src/presentation/blocs/auth_event.dart';
import 'package:staff_authentication/src/presentation/blocs/auth_state.dart'; import 'package:staff_authentication/src/presentation/blocs/auth_state.dart';
import 'package:staff_authentication/src/presentation/blocs/auth_bloc.dart';
import '../widgets/phone_verification_page/phone_input.dart';
import '../widgets/phone_verification_page/otp_verification.dart';
import 'package:staff_authentication/staff_authentication.dart'; import 'package:staff_authentication/staff_authentication.dart';
import '../navigation/auth_navigator.dart'; // Import the extension import '../navigation/auth_navigator.dart'; // Import the extension
import '../widgets/phone_verification_page/otp_verification.dart';
import '../widgets/phone_verification_page/phone_input.dart';
/// A combined page for phone number entry and OTP verification. /// A combined page for phone number entry and OTP verification.
/// ///

View File

@@ -9,15 +9,29 @@ import 'phone_input/phone_input_form_field.dart';
import 'phone_input/phone_input_header.dart'; import 'phone_input/phone_input_header.dart';
/// A widget that displays the phone number entry UI. /// A widget that displays the phone number entry UI.
class PhoneInput extends StatelessWidget { class PhoneInput extends StatefulWidget {
/// Creates a [PhoneInput].
const PhoneInput({super.key, required this.state, required this.onSendCode});
/// The current state of the authentication process. /// The current state of the authentication process.
final AuthState state; final AuthState state;
/// Callback for when the "Send Code" action is triggered. /// Callback for when the "Send Code" action is triggered.
final VoidCallback onSendCode; final VoidCallback onSendCode;
/// Creates a [PhoneInput]. @override
const PhoneInput({super.key, required this.state, required this.onSendCode}); State<PhoneInput> createState() => _PhoneInputState();
}
class _PhoneInputState extends State<PhoneInput> {
void _handlePhoneChanged(String value) {
if (!mounted) return;
final AuthBloc bloc = context.read<AuthBloc>();
if (!bloc.isClosed) {
bloc.add(AuthPhoneUpdated(value));
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -35,19 +49,18 @@ class PhoneInput extends StatelessWidget {
const PhoneInputHeader(), const PhoneInputHeader(),
const SizedBox(height: UiConstants.space8), const SizedBox(height: UiConstants.space8),
PhoneInputFormField( PhoneInputFormField(
initialValue: state.phoneNumber, initialValue: widget.state.phoneNumber,
error: state.errorMessage ?? '', error: widget.state.errorMessage ?? '',
onChanged: (String value) { onChanged: _handlePhoneChanged,
BlocProvider.of<AuthBloc>(
context,
).add(AuthPhoneUpdated(value));
},
), ),
], ],
), ),
), ),
), ),
PhoneInputActions(isLoading: state.isLoading, onSendCode: onSendCode), PhoneInputActions(
isLoading: widget.state.isLoading,
onSendCode: widget.onSendCode,
),
], ],
); );
} }

View File

@@ -44,7 +44,7 @@ class HomeRepositoryImpl implements HomeRepository {
if (shiftDate == null) return false; if (shiftDate == null) return false;
final isDateMatch = DateFormat('yyyy-MM-dd').format(shiftDate) == targetYmd; final isDateMatch = DateFormat('yyyy-MM-dd').format(shiftDate) == targetYmd;
final isAssigned = app.status is Known && (app.status as Known).value == ApplicationStatus.ACCEPTED; final isAssigned = app.status is Known && ((app.status as Known).value == ApplicationStatus.ACCEPTED || (app.status as Known).value == ApplicationStatus.CONFIRMED);
return isDateMatch && isAssigned; return isDateMatch && isAssigned;
}) })

View File

@@ -13,7 +13,6 @@ import 'package:staff_home/src/presentation/widgets/home_page/quick_action_item.
import 'package:staff_home/src/presentation/widgets/home_page/recommended_shift_card.dart'; import 'package:staff_home/src/presentation/widgets/home_page/recommended_shift_card.dart';
import 'package:staff_home/src/presentation/widgets/home_page/section_header.dart'; import 'package:staff_home/src/presentation/widgets/home_page/section_header.dart';
import 'package:staff_home/src/presentation/widgets/shift_card.dart'; import 'package:staff_home/src/presentation/widgets/shift_card.dart';
import 'package:staff_home/src/presentation/widgets/worker/auto_match_toggle.dart';
/// The home page for the staff worker application. /// The home page for the staff worker application.
/// ///

View File

@@ -5,6 +5,7 @@ import 'package:intl/intl.dart';
import 'package:design_system/design_system.dart'; import 'package:design_system/design_system.dart';
import 'package:krow_domain/krow_domain.dart'; import 'package:krow_domain/krow_domain.dart';
import '../navigation/home_navigator.dart';
class ShiftCard extends StatefulWidget { class ShiftCard extends StatefulWidget {
final Shift shift; final Shift shift;
@@ -73,10 +74,7 @@ class _ShiftCardState extends State<ShiftCard> {
? null ? null
: () { : () {
setState(() => isExpanded = !isExpanded); setState(() => isExpanded = !isExpanded);
Modular.to.pushNamed( Modular.to.pushShiftDetails(widget.shift);
'/shift-details/${widget.shift.id}',
arguments: widget.shift,
);
}, },
child: Container( child: Container(
margin: const EdgeInsets.only(bottom: 12), margin: const EdgeInsets.only(bottom: 12),