Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emergency_contact_view #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added fonts/Urbanist-Regular.ttf
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:get/get.dart';

import '../controllers/emergency_contact_controller.dart';

class EmergencyContactBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<EmergencyContactController>(
() => EmergencyContactController(),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class EmergencyContactController extends GetxController {
final formKey = GlobalKey<FormState>();

@override
void onInit() {
super.onInit();
}

@override
void onReady() {
super.onReady();
}

@override
void onClose() {
super.onClose();
}

// Observables for each form field
var name = ''.obs;
var mobileNumber = ''.obs;
var email = ''.obs;
var relation = ''.obs;

// Method to validate and save form
void saveDetails() {
if (formKey.currentState!.validate()) {
formKey.currentState!.save();
// Perform additional logic for saving the data
Get.snackbar('Success', 'Emergency contact details saved successfully',
snackPosition: SnackPosition.BOTTOM);
} else {
Get.snackbar(
'Error',
'Please fill all fields correctly',
snackPosition: SnackPosition.BOTTOM,
);
}
}
}

257 changes: 257 additions & 0 deletions lib/app/modules/emergency_contact/views/emergency_contact_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:here_for_you_app/app/modules/emergency_contact/controllers/emergency_contact_controller.dart'; // Import the controller

class EmergencyContactView extends StatelessWidget {
final EmergencyContactController _controller = Get.put(EmergencyContactController());

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(
Icons.arrow_back,
size: 35,
),
onPressed: () {
Get.back(); // Navigate to the previous screen
},
),
titleSpacing: -10, // Make title align close to the back button
title: Text(
'Emergency Contact',
style: TextStyle(
fontFamily: 'Urbanist',
fontWeight: FontWeight.bold,
fontSize: 25,
),
),
backgroundColor: Colors.transparent,
elevation: 0, // Remove shadow
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _controller.formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Name Label and TextFormField with Shadow
SizedBox(height: 20),
Text(
'Name',
style: TextStyle(
fontFamily: 'Urbanist',
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 7),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(35),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
spreadRadius: 3,
blurRadius: 6,
offset: Offset(0, 3), // Shadow position
),
],
),
child: TextFormField(
decoration: InputDecoration(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a separate file of custom textform field, and use that widget as reusable component

hintText: 'Enter emergency contact name',
filled: true, // Enable filling
fillColor: Colors.white, // Set the fill color to white
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(35), // Rounded corners
),
contentPadding: EdgeInsets.symmetric(horizontal:14,vertical: 8), // Consistent height
),
style: TextStyle(fontFamily: 'Urbanist'),
onSaved: (value) => _controller.name.value = value!,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a name';
}
return null;
},
),
),
SizedBox(height: 20),

// Mobile Number Label and TextFormField with Shadow
Text(
'Mobile Number',
style: TextStyle(
fontFamily: 'Urbanist',
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 7),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(35),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
spreadRadius: 3,
blurRadius: 6,
offset: Offset(0, 3), // Shadow position
),
],
),
child: TextFormField(
decoration: InputDecoration(
hintText: 'Enter emergency contact number',
filled: true, // Enable filling
fillColor: Colors.white, // Set the fill color to white
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(35), // Rounded corners
),
contentPadding: EdgeInsets.symmetric(horizontal:14,vertical: 8), // Consistent height
),
keyboardType: TextInputType.phone,
style: TextStyle(fontFamily: 'Urbanist'),
onSaved: (value) => _controller.mobileNumber.value = value!,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a mobile number';
}
if (value.length != 10) {
return 'Mobile number should be 10 digits';
}
return null;
},
),
),
SizedBox(height: 20),

// Email Label and TextFormField with Shadow
Text(
'Email',
style: TextStyle(
fontFamily: 'Urbanist',
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 7),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(35),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
spreadRadius: 3,
blurRadius: 6,
offset: Offset(0, 3), // Shadow position
),
],
),
child: TextFormField(
decoration: InputDecoration(
hintText: 'Enter emergency contact email',
filled: true, // Enable filling
fillColor: Colors.white, // Set the fill color to white
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(35),
),
contentPadding: EdgeInsets.symmetric(horizontal:14,vertical: 8), // Consistent height
),
keyboardType: TextInputType.emailAddress,
style: TextStyle(fontFamily: 'Urbanist'),
onSaved: (value) => _controller.email.value = value!,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter an email';
}
if (!GetUtils.isEmail(value)) {
return 'Enter a valid email';
}
return null;
},
),
),
SizedBox(height: 20),

// Relation Label and TextFormField with Shadow
Text(
'Relation',
style: TextStyle(
fontFamily: 'Urbanist',
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 7),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(35),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
spreadRadius: 3,
blurRadius: 6,
offset: Offset(0, 3), // Shadow position
),
],
),
child: TextFormField(
decoration: InputDecoration(
hintText: 'How is emergency contact related to you?',
hintStyle: TextStyle(
fontFamily: 'Urbanist',
fontSize: 13,
),
filled: true, // Enable filling
fillColor: Colors.white, // Set the fill color to white
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(35), // Rounded corners
),
contentPadding: EdgeInsets.symmetric(horizontal:12,vertical: 8), // Consistent height
),
style: TextStyle(fontFamily: 'Urbanist'),
onSaved: (value) => _controller.relation.value = value!,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter the relation';
}
return null;
},
),
),
SizedBox(height: 30),

// Save Button
Center(
child: ElevatedButton(
onPressed: () {
_controller.saveDetails();
},
child: Text(
'Save Details',
style: TextStyle(
fontFamily: 'Urbanist',
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black,
padding: EdgeInsets.symmetric(horizontal: 105, vertical: 12),
textStyle: TextStyle(fontSize: 10),
),
),
),
],
),
),
),
);
}
}
9 changes: 8 additions & 1 deletion lib/app/routes/app_pages.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:get/get.dart';

import '../modules/emergency_contact/bindings/emergency_contact_binding.dart';
import '../modules/emergency_contact/views/emergency_contact_view.dart';
import '../modules/home/bindings/home_binding.dart';
import '../modules/home/views/home_view.dart';

Expand All @@ -8,13 +10,18 @@ part 'app_routes.dart';
class AppPages {
AppPages._();

static const INITIAL = Routes.HOME;
static const INITIAL = Routes.EMERGENCY_CONTACT;

static final routes = [
GetPage(
name: _Paths.HOME,
page: () => const HomeView(),
binding: HomeBinding(),
),
GetPage(
name: _Paths.EMERGENCY_CONTACT,
page: () =>EmergencyContactView(),
binding: EmergencyContactBinding(),
),
];
}
2 changes: 2 additions & 0 deletions lib/app/routes/app_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ part of 'app_pages.dart';
abstract class Routes {
Routes._();
static const HOME = _Paths.HOME;
static const EMERGENCY_CONTACT = _Paths.EMERGENCY_CONTACT;
}

abstract class _Paths {
_Paths._();
static const HOME = '/home';
static const EMERGENCY_CONTACT = '/emergency-contact';
}
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void main() {
title: "Application",
initialRoute: AppPages.INITIAL,
getPages: AppPages.routes,
debugShowCheckedModeBanner: false,
),
);
}
Loading