-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22202e8
commit 76e1684
Showing
12 changed files
with
697 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:recipes/core/core.dart'; | ||
|
||
import '../../../login/presentation/screens/login.dart'; | ||
|
||
|
||
|
||
class CustomDrawer extends ConsumerWidget { | ||
const CustomDrawer({ super.key}); | ||
|
||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Drawer( | ||
child: ListView( | ||
padding: EdgeInsets.zero, | ||
children: [ | ||
const DrawerHeader( | ||
decoration: BoxDecoration( | ||
color: AppColors.deepBlue, | ||
), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
CircleAvatar( | ||
radius: 30, | ||
backgroundImage: AssetImage(AppAssets.profile), | ||
), | ||
SizedBox(height: 10), | ||
Text( | ||
'John Doe', | ||
style: TextStyle( | ||
color: Colors.white, | ||
fontSize: 20, | ||
), | ||
), | ||
Text( | ||
'johndoe@example.com', | ||
style: TextStyle( | ||
color: Colors.white70, | ||
fontSize: 14, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
ListTile( | ||
leading: const Icon(Icons.home), | ||
title: const Text('Home'), | ||
onTap: () { | ||
Navigator.pop(context); // Close the drawer | ||
context.goNamed(Routes.home.name); | ||
}, | ||
), | ||
ListTile( | ||
leading: const Icon(Icons.favorite), | ||
title: const Text('Favorites'), | ||
onTap: () { | ||
Navigator.pop(context); // Close the drawer | ||
context.goNamed(Routes.favorites.name); | ||
}, | ||
), | ||
ListTile( | ||
leading: const Icon(Icons.settings), | ||
title: const Text('Settings'), | ||
onTap: () { | ||
Navigator.pop(context); // Close the drawer | ||
// context.goNamed(Routes.settings.name); | ||
}, | ||
), | ||
ListTile( | ||
leading: const Icon(Icons.person), | ||
title: const Text('Profile'), | ||
onTap: () { | ||
Navigator.pop(context); // Close the drawer | ||
//context.goNamed(Routes.profile.name); | ||
}, | ||
), | ||
const Divider(), | ||
ListTile( | ||
leading: const Icon(Icons.logout), | ||
title: const Text('Logout'), | ||
onTap: () { | ||
/* Navigator.pushReplacement( | ||
context, | ||
MaterialPageRoute(builder: (context) => const LoginScreen()), | ||
);*/ | ||
// Handle logout | ||
}, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:hive/hive.dart'; | ||
import 'package:recipes/configs/configs.dart'; | ||
import 'package:collection/collection.dart'; | ||
import '../../../home/presentation/screens/home.dart'; | ||
import '../../../register/infrastructure/dto/user_model.dart'; | ||
|
||
class LoginScreen extends ConsumerStatefulWidget { | ||
const LoginScreen({Key? key}) : super(key: key); | ||
|
||
@override | ||
_LoginScreenState createState() => _LoginScreenState(); | ||
} | ||
|
||
class _LoginScreenState extends ConsumerState<LoginScreen> { | ||
final TextEditingController _emailController = TextEditingController(); | ||
final TextEditingController _passwordController = TextEditingController(); | ||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); | ||
|
||
Future<void> _login() async { | ||
if (_formKey.currentState?.validate() ?? false) { | ||
final Box<User> userBox = Hive.box<User>('users'); | ||
final String email = _emailController.text; | ||
final String password = _passwordController.text; | ||
|
||
final User? user = userBox.values.firstWhereOrNull( | ||
(user) => user.email == email && user.password == password, | ||
//orElse: () => null, | ||
); | ||
|
||
if (user != null) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text('Login Successful')), | ||
); | ||
Navigator.pushReplacement( | ||
context, | ||
MaterialPageRoute(builder: (context) => const HomeScreen()), | ||
); | ||
} else { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar(content: Text('Invalid email or password')), | ||
); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Login'), | ||
), | ||
body: Padding( | ||
padding: EdgeInsets.all(AppDimensions.normalize(4)), | ||
child: Form( | ||
key: _formKey, | ||
child: ListView( | ||
children: [ | ||
TextFormField( | ||
controller: _emailController, | ||
decoration: const InputDecoration( | ||
labelText: 'Email', | ||
), | ||
validator: (value) { | ||
if (value == null || value.isEmpty) { | ||
return 'Please enter your email'; | ||
} | ||
if (!RegExp(r'^[^@]+@[^@]+\.[^@]+').hasMatch(value)) { | ||
return 'Please enter a valid email'; | ||
} | ||
return null; | ||
}, | ||
), | ||
Space.yf(1.0), | ||
TextFormField( | ||
controller: _passwordController, | ||
decoration: const InputDecoration( | ||
labelText: 'Password', | ||
), | ||
obscureText: true, | ||
validator: (value) { | ||
if (value == null || value.isEmpty) { | ||
return 'Please enter your password'; | ||
} | ||
return null; | ||
}, | ||
), | ||
Space.yf(2.0), | ||
ElevatedButton( | ||
onPressed: _login, | ||
child: const Text('Login'), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:hive/hive.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'user_model.freezed.dart'; | ||
part 'user_model.g.dart'; | ||
|
||
@freezed | ||
class User with _$User { | ||
@HiveType(typeId: 1) | ||
const factory User({ | ||
@HiveField(0) required String id, | ||
@HiveField(1) required String name, | ||
@HiveField(2) required String email, | ||
@HiveField(3) required String password, | ||
}) = _User; | ||
|
||
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json); | ||
} | ||
|
||
class UserAdapter extends TypeAdapter<User> { | ||
@override | ||
final int typeId = 1; | ||
|
||
@override | ||
User read(BinaryReader reader) { | ||
return User( | ||
id: reader.readString(), | ||
name: reader.readString(), | ||
email: reader.readString(), | ||
password: reader.readString(), | ||
); | ||
} | ||
|
||
@override | ||
void write(BinaryWriter writer, User obj) { | ||
writer.writeString(obj.id); | ||
writer.writeString(obj.name); | ||
writer.writeString(obj.email); | ||
writer.writeString(obj.password); | ||
} | ||
} |
Oops, something went wrong.