refactor: integrate email field with controller for dynamic updates in PersonalInfoForm
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
|
|
||||||
|
import 'package:core_localization/core_localization.dart';
|
||||||
|
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:core_localization/core_localization.dart';
|
|
||||||
import 'package:design_system/design_system.dart';
|
|
||||||
|
|
||||||
import '../blocs/personal_info_bloc.dart';
|
import '../blocs/personal_info_bloc.dart';
|
||||||
import '../blocs/personal_info_event.dart';
|
|
||||||
import '../blocs/personal_info_state.dart';
|
import '../blocs/personal_info_state.dart';
|
||||||
import '../widgets/personal_info_content.dart';
|
import '../widgets/personal_info_content.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -32,28 +32,41 @@ class PersonalInfoContent extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PersonalInfoContentState extends State<PersonalInfoContent> {
|
class _PersonalInfoContentState extends State<PersonalInfoContent> {
|
||||||
|
late final TextEditingController _emailController;
|
||||||
late final TextEditingController _phoneController;
|
late final TextEditingController _phoneController;
|
||||||
late final TextEditingController _locationsController;
|
late final TextEditingController _locationsController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_emailController = TextEditingController(text: widget.staff.email);
|
||||||
_phoneController = TextEditingController(text: widget.staff.phone ?? '');
|
_phoneController = TextEditingController(text: widget.staff.phone ?? '');
|
||||||
_locationsController = TextEditingController(text: widget.staff.preferredLocations?.join(', ')?? '');
|
_locationsController = TextEditingController(text: widget.staff.preferredLocations?.join(', ')?? '');
|
||||||
|
|
||||||
// Listen to changes and update BLoC
|
// Listen to changes and update BLoC
|
||||||
|
_emailController.addListener(_onEmailChanged);
|
||||||
_phoneController.addListener(_onPhoneChanged);
|
_phoneController.addListener(_onPhoneChanged);
|
||||||
_locationsController.addListener(_onAddressChanged);
|
_locationsController.addListener(_onAddressChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_emailController.dispose();
|
||||||
_phoneController.dispose();
|
_phoneController.dispose();
|
||||||
_locationsController.dispose();
|
_locationsController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void _onEmailChanged() {
|
||||||
|
context.read<PersonalInfoBloc>().add(
|
||||||
|
PersonalInfoFieldChanged(
|
||||||
|
field: 'email',
|
||||||
|
value: _emailController.text,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void _onPhoneChanged() {
|
void _onPhoneChanged() {
|
||||||
context.read<PersonalInfoBloc>().add(
|
context.read<PersonalInfoBloc>().add(
|
||||||
PersonalInfoFieldChanged(
|
PersonalInfoFieldChanged(
|
||||||
@@ -114,6 +127,7 @@ class _PersonalInfoContentState extends State<PersonalInfoContent> {
|
|||||||
PersonalInfoForm(
|
PersonalInfoForm(
|
||||||
fullName: widget.staff.name,
|
fullName: widget.staff.name,
|
||||||
email: widget.staff.email,
|
email: widget.staff.email,
|
||||||
|
emailController: _emailController,
|
||||||
phoneController: _phoneController,
|
phoneController: _phoneController,
|
||||||
locationsController: _locationsController,
|
locationsController: _locationsController,
|
||||||
enabled: !isSaving,
|
enabled: !isSaving,
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ class PersonalInfoForm extends StatelessWidget {
|
|||||||
/// The staff member's email (read-only).
|
/// The staff member's email (read-only).
|
||||||
final String email;
|
final String email;
|
||||||
|
|
||||||
|
/// Controller for the email field.
|
||||||
|
final TextEditingController emailController;
|
||||||
|
|
||||||
/// Controller for the phone number field.
|
/// Controller for the phone number field.
|
||||||
final TextEditingController phoneController;
|
final TextEditingController phoneController;
|
||||||
|
|
||||||
@@ -29,6 +32,7 @@ class PersonalInfoForm extends StatelessWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.fullName,
|
required this.fullName,
|
||||||
required this.email,
|
required this.email,
|
||||||
|
required this.emailController,
|
||||||
required this.phoneController,
|
required this.phoneController,
|
||||||
required this.locationsController,
|
required this.locationsController,
|
||||||
this.enabled = true,
|
this.enabled = true,
|
||||||
@@ -48,7 +52,13 @@ class PersonalInfoForm extends StatelessWidget {
|
|||||||
|
|
||||||
_FieldLabel(text: i18n.email_label),
|
_FieldLabel(text: i18n.email_label),
|
||||||
const SizedBox(height: UiConstants.space2),
|
const SizedBox(height: UiConstants.space2),
|
||||||
_ReadOnlyField(value: email),
|
_EditableField(
|
||||||
|
controller: emailController,
|
||||||
|
hint: i18n.email_label,
|
||||||
|
enabled: enabled,
|
||||||
|
keyboardType: TextInputType.emailAddress,
|
||||||
|
autofillHints: const [AutofillHints.email],
|
||||||
|
),
|
||||||
const SizedBox(height: UiConstants.space4),
|
const SizedBox(height: UiConstants.space4),
|
||||||
|
|
||||||
_FieldLabel(text: i18n.phone_label),
|
_FieldLabel(text: i18n.phone_label),
|
||||||
@@ -122,11 +132,15 @@ class _EditableField extends StatelessWidget {
|
|||||||
final TextEditingController controller;
|
final TextEditingController controller;
|
||||||
final String hint;
|
final String hint;
|
||||||
final bool enabled;
|
final bool enabled;
|
||||||
|
final TextInputType? keyboardType;
|
||||||
|
final Iterable<String>? autofillHints;
|
||||||
|
|
||||||
const _EditableField({
|
const _EditableField({
|
||||||
required this.controller,
|
required this.controller,
|
||||||
required this.hint,
|
required this.hint,
|
||||||
this.enabled = true,
|
this.enabled = true,
|
||||||
|
this.keyboardType,
|
||||||
|
this.autofillHints,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -134,6 +148,8 @@ class _EditableField extends StatelessWidget {
|
|||||||
return TextField(
|
return TextField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
|
keyboardType: keyboardType,
|
||||||
|
autofillHints: autofillHints,
|
||||||
style: UiTypography.body2r.copyWith(color: UiColors.textPrimary),
|
style: UiTypography.body2r.copyWith(color: UiColors.textPrimary),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: hint,
|
hintText: hint,
|
||||||
|
|||||||
Reference in New Issue
Block a user