Notes
![]() ![]() Notes - notes.io |
import 'package:intl_phone_field/intl_phone_field.dart';
import 'package:intl_phone_field/phone_number.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'screens/log_in_screen.dart';
class LogInPage extends StatelessWidget {
const LogInPage({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: WelcomeScreen(),
);
}
}
class WelcomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 50.0),
child: Image.asset("assets/images/family.png"),
),
const SizedBox(height: 150),
Column(
children: const [
Icon(Icons.refresh, size: 48, color: Colors.teal),
SizedBox(height: 10),
Text.rich(
TextSpan(
children: [
TextSpan(
text: 'Fam',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.black),
),
TextSpan(
text: 'Tech',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.grey),
),
],
),
),
],
),
const SizedBox(height: 40),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0),
child: Column(
children: [
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const LoginScreen()));
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black,
minimumSize: const Size(double.infinity, 50),
),
child: const Text("Login",
style: TextStyle(color: Colors.white)),
),
const SizedBox(height: 10),
OutlinedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RegisterScreen()));
},
style: OutlinedButton.styleFrom(
minimumSize: const Size(double.infinity, 50)),
child: const Text("Sign up",
style: TextStyle(color: Colors.black)),
),
],
),
),
const Spacer(),
],
),
),
);
}
}
class RegisterScreen extends StatefulWidget {
@override
State<RegisterScreen> createState() => _RegisterScreenState();
}
class _RegisterScreenState extends State<RegisterScreen> {
final _formKey = GlobalKey<FormState>();
bool agreeToPrivacy = false;
String? selectedDay;
String? selectedMonth;
String? selectedYear;
String? selectedBloodGroup;
String? selectedGender;
String? email;
String? password;
String? confirmPassword;
PhoneNumber? phoneNumber;
bool _obscurePassword = true;
bool _obscureConfirmPassword = true;
List<String> dayList =
List.generate(31, (i) => (i + 1).toString().padLeft(2, '0'));
final List<String> monthNames = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];
final List<String> years =
List.generate(100, (i) => (DateTime.now().year - i).toString());
final List<String> bloodGroups = [
'A+',
'A-',
'B+',
'B-',
'AB+',
'AB-',
'O+',
'O-'
];
String? requiredValidator(String? value) =>
(value == null || value.isEmpty) ? 'Required' : null;
String? emailValidator(String? value) {
if (value == null || value.isEmpty) return 'Required';
final emailRegex = RegExp(r'^[w-.]+@([w-]+.)+[w-]{2,4}$');
return emailRegex.hasMatch(value) ? null : 'Invalid email';
}
String? passwordValidator(String? value) {
if (value == null || value.isEmpty) return 'Required';
return value.length >= 6 ? null : 'Min 6 chars';
}
String? confirmPasswordValidator(String? value) {
return (value != password) ? 'Passwords don't match' : null;
}
void updateDays() {
if (selectedMonth != null) {
int month = monthNames.indexOf(selectedMonth!) + 1;
int daysInMonth = (selectedMonth == 'February')
? 29
: [1, 3, 5, 7, 8, 10, 12].contains(month)
? 31
: 30;
setState(() {
dayList = List.generate(
daysInMonth, (i) => (i + 1).toString().padLeft(2, '0'));
});
}
}
void updateDaysForYear() {
if (selectedYear != null && selectedMonth == 'February') {
int year = int.parse(selectedYear!);
bool isLeap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
setState(() {
dayList = List.generate(
isLeap ? 29 : 28, (i) => (i + 1).toString().padLeft(2, '0'));
});
}
}
Future<void> registerWithEmail() async {
try {
final auth = FirebaseAuth.instance;
await auth.createUserWithEmailAndPassword(
email: email!, password: password!);
if (mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text("Account Created")));
Navigator.pop(context);
}
} on FirebaseAuthException catch (e) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(e.message ?? 'Error occurred')));
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Create Account"),
backgroundColor: Colors.white,
foregroundColor: Colors.black,
elevation: 0,
),
body: Padding(
padding: const EdgeInsets.all(24.0),
child: Form(
key: _formKey,
child: ListView(
children: [
Row(
children: [
Expanded(
child: TextFormField(
decoration: const InputDecoration(
labelText: "First Name",
prefixIcon: Icon(Icons.person)),
validator: requiredValidator)),
const SizedBox(width: 10),
Expanded(
child: TextFormField(
decoration: const InputDecoration(
labelText: "Last Name",
prefixIcon: Icon(Icons.person)),
validator: requiredValidator)),
],
),
const SizedBox(height: 10),
TextFormField(
decoration: const InputDecoration(
labelText: "E-Mail", prefixIcon: Icon(Icons.email)),
keyboardType: TextInputType.emailAddress,
validator: emailValidator,
onChanged: (value) => email = value,
),
const SizedBox(height: 10),
IntlPhoneField(
decoration: const InputDecoration(
labelText: 'Phone Number', border: OutlineInputBorder()),
initialCountryCode: 'TR',
keyboardType: TextInputType.phone,
onChanged: (phone) => phoneNumber = phone,
),
const SizedBox(height: 10),
// Gender Dropdown
DropdownButtonFormField<String>(
decoration: const InputDecoration(
labelText: "Gender",
prefixIcon: Icon(Icons.person_outline),
),
value: selectedGender,
items: ['Male', 'Female', 'Other']
.map((gender) =>
DropdownMenuItem(value: gender, child: Text(gender)))
.toList(),
onChanged: (val) => setState(() => selectedGender = val),
validator: requiredValidator,
),
const SizedBox(height: 10),
DropdownButtonFormField<String>(
decoration: const InputDecoration(
labelText: "Blood Group",
prefixIcon: Icon(Icons.bloodtype)),
value: selectedBloodGroup,
items: bloodGroups
.map((bg) => DropdownMenuItem(value: bg, child: Text(bg)))
.toList(),
onChanged: (val) => setState(() => selectedBloodGroup = val),
validator: requiredValidator,
),
const SizedBox(height: 10),
TextFormField(
obscureText: _obscurePassword,
decoration: InputDecoration(
labelText: "Password",
prefixIcon: const Icon(Icons.lock),
suffixIcon: IconButton(
icon: Icon(_obscurePassword
? Icons.visibility
: Icons.visibility_off),
onPressed: () =>
setState(() => _obscurePassword = !_obscurePassword),
),
),
validator: passwordValidator,
onChanged: (value) => password = value,
),
const SizedBox(height: 10),
TextFormField(
obscureText: _obscureConfirmPassword,
decoration: InputDecoration(
labelText: "Confirm Password",
prefixIcon: const Icon(Icons.lock),
suffixIcon: IconButton(
icon: Icon(_obscureConfirmPassword
? Icons.visibility
: Icons.visibility_off),
onPressed: () => setState(() =>
_obscureConfirmPassword = !_obscureConfirmPassword),
),
),
validator: confirmPasswordValidator,
onChanged: (value) => confirmPassword = value,
),
CheckboxListTile(
value: agreeToPrivacy,
onChanged: (value) => setState(() => agreeToPrivacy = value!),
title: const Text("I agree to Privacy Policy and Terms of Use"),
controlAffinity: ListTileControlAffinity.leading,
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: agreeToPrivacy
? () {
if (_formKey.currentState!.validate()) {
registerWithEmail();
}
}
: null,
style: ElevatedButton.styleFrom(
minimumSize: const Size(double.infinity, 50),
backgroundColor: Colors.blue),
child: const Text("Create Account"),
),
],
),
),
),
);
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team