medora-provider/lib/screens/doctor_screens/address_screen.dart
DhanshCOSQ 66c3b2fb9c Patient registration complete with authentication flow fixed (#3)
Patient registration complete with authentication flow fixed

Co-authored-by: Benoy Bose <benoybose@gmail.com>
Co-authored-by: Jipson George <152465898+Jipson-cosq@users.noreply.github.com>
Reviewed-on: cosqnet/telemednet#3
Reviewed-by: Benoy Bose <benoybose@cosq.net>
Co-authored-by: DhanshCOSQ <dhanshas@cosq.net>
Co-committed-by: DhanshCOSQ <dhanshas@cosq.net>
2024-10-31 14:20:35 +00:00

169 lines
5.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:telemednet/screens/doctor_screens/profile_description_screen.dart';
import '../../common/custom_style.dart';
import '../../controllers/doctor _controller.dart';
import '../../route_names.dart';
class DoctorAddressScreen extends StatefulWidget {
final DoctorController controller;
const DoctorAddressScreen({Key? key, required this.controller})
: super(key: key);
@override
State<DoctorAddressScreen> createState() => _DoctorAddressScreenState();
}
class _DoctorAddressScreenState extends State<DoctorAddressScreen> {
final _floorBuildingController = TextEditingController();
final _streetController = TextEditingController();
final _cityController = TextEditingController();
final _stateController = TextEditingController();
final _countryController = TextEditingController();
final _postalCodeController = TextEditingController();
late AddressController addressController;
@override
void initState() {
super.initState();
// Initialize the AddressController
addressController = widget.controller.addressController;
// Set the initial values from the address model
_floorBuildingController.text = addressController.model.floorBuilding ?? '';
_streetController.text = addressController.model.street ?? '';
_cityController.text = addressController.model.city ?? '';
_stateController.text = addressController.model.state ?? '';
_countryController.text = addressController.model.country ?? '';
_postalCodeController.text = addressController.model.postalCode ?? '';
}
@override
void dispose() {
_floorBuildingController.dispose();
_streetController.dispose();
_cityController.dispose();
_stateController.dispose();
_countryController.dispose();
_postalCodeController.dispose();
super.dispose();
}
bool _validateAndProceed() {
// Update the address model
addressController.updateFloorBuilding(_floorBuildingController.text);
addressController.updateStreet(_streetController.text);
addressController.updateCity(_cityController.text);
addressController.updateState(_stateController.text);
addressController.updateCountry(_countryController.text);
addressController.updatePostalCode(_postalCodeController.text);
// Validate the address fields
if (_areFieldsValid()) {
return true;
}
showErrorSnackBar(context, 'Please fill in all required fields');
return false;
}
bool _areFieldsValid() {
return _floorBuildingController.text.isNotEmpty &&
_streetController.text.isNotEmpty &&
_cityController.text.isNotEmpty &&
_stateController.text.isNotEmpty &&
_countryController.text.isNotEmpty &&
_postalCodeController.text.isNotEmpty;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Address Details'),
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildTextField(
'Floor, Building',
'Enter floor and building',
_floorBuildingController,
),
_buildTextField(
'Street or Road',
'Enter street or road',
_streetController,
),
_buildTextField(
'City',
'Enter city',
_cityController,
),
_buildTextField(
'State',
'Enter state',
_stateController,
),
_buildTextField(
'Country',
'Enter country',
_countryController,
),
_buildTextField(
'Postal Code',
'Enter postal code',
_postalCodeController,
),
],
),
),
bottomNavigationBar: Padding(
padding: const EdgeInsets.all(16),
child: ElevatedButton(
onPressed: () {
Navigator.pushNamed(
context,
RouteNames.profileDescriptionScreen,
arguments: ProfileDescriptionScreen(
controller:
widget.controller, // Pass the same controller instance
),
);
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
backgroundColor: const Color(0xFF5BC0DE),
),
child: const Icon(
Icons.arrow_forward_ios,
color: Colors.white,
),
),
),
);
}
Widget _buildTextField(
String label,
String hint,
TextEditingController controller,
) {
return Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: TextField(
controller: controller,
decoration: InputDecoration(
labelText: label,
hintText: hint,
border: const OutlineInputBorder(),
),
),
);
}
}