medora-provider/lib/screens/authentication/launch_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

222 lines
6.7 KiB
Dart

import 'dart:async';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:telemednet/data/services/navigation_service.dart';
import 'package:telemednet/route_names.dart';
import 'package:telemednet/screens/authentication/sign_up_screen.dart';
import 'package:telemednet/widgets/primary_button.dart';
class LaunchScreen extends StatefulWidget {
const LaunchScreen({super.key});
@override
State<LaunchScreen> createState() => _LaunchScreenState();
}
class _LaunchScreenState extends State<LaunchScreen> {
String? selectedUserType;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('images/cover-picture.jpg'),
fit: BoxFit.cover,
),
),
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24.0),
child: Card(
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return _buildLoadingWidget();
} else if (snapshot.hasData) {
_fetchProfileAndNavigate(context);
return _buildLoadingWidget();
} else {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Register',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
const Text(
'Who are you?',
style: TextStyle(
color: Colors.grey,
fontSize: 16,
),
),
const SizedBox(height: 24),
_buildUserTypeSelection(context),
],
);
}
},
),
),
),
),
),
),
);
}
Widget _buildLoadingWidget() {
return const SizedBox(
height: 120,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(),
SizedBox(height: 12),
Text('Please wait...'),
],
),
),
);
}
Widget _buildUserTypeSelection(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
_buildSelectionCard(
title: 'Doctor',
description: 'Can organise and approve appointments',
icon: Icons.medical_services,
isSelected: selectedUserType == 'doctor',
onTap: () => setState(() => selectedUserType = 'doctor'),
),
const SizedBox(height: 12),
_buildSelectionCard(
title: 'Patient',
description: 'Can book appointments',
icon: Icons.person,
isSelected: selectedUserType == 'patient',
onTap: () => setState(() => selectedUserType = 'patient'),
),
const SizedBox(height: 24),
SizedBox(
width: double.infinity,
child: PrimaryButton(
onPressed: selectedUserType != null
? () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SignUpScreen(
selectedUserType: selectedUserType!,
),
),
)
: null,
text: 'Next',
),
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Already have an account?'),
TextButton(
onPressed: () {
Navigator.of(context).pushNamed(RouteNames.signIn);
},
child: const Text(
'Login',
style: TextStyle(color: Colors.blue),
),
),
],
),
],
);
}
Widget _buildSelectionCard({
required String title,
required String description,
required IconData icon,
required bool isSelected,
required VoidCallback onTap,
}) {
return InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: isSelected ? Colors.blue : Colors.grey.shade300,
width: isSelected ? 2 : 1,
),
borderRadius: BorderRadius.circular(12),
color: isSelected ? Colors.blue.shade50 : Colors.white,
),
padding: const EdgeInsets.all(16),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.blue.shade100,
borderRadius: BorderRadius.circular(8),
),
child: Icon(icon, color: Colors.blue, size: 24),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 4),
Text(
description,
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade600,
),
),
],
),
),
],
),
),
);
}
Future<void> _fetchProfileAndNavigate(BuildContext context) async {
if (mounted) {
await NavigationService.handleUserNavigation(context);
}
}
}