Skip to content

Commit

Permalink
feat: profile screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ravindranag committed Apr 17, 2023
1 parent fbd6450 commit b7c953f
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 13 deletions.
19 changes: 19 additions & 0 deletions lib/src/features/authentication/model/user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class User {
String? uid;
String name;
String email;

User(
this.uid,
this.name,
this.email,
);

toJson() {
return {
'name': name,
'email': email,
'userId': uid
};
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:courses_app/src/constants/images.dart';
import 'package:courses_app/src/features/profile/screen/profile/profile_screen.dart';
import 'package:courses_app/src/repository/auth_repository.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -26,7 +28,29 @@ class DashboardSliverAppBar extends StatelessWidget {
scale: scrolled ? 0.0 : 1.0,
child: CircleAvatar(
radius: scrolled ? 0.0 : 30.0,
child: const Icon(Icons.person),
child: InkResponse(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return const ProfileScreen();
},
),
);
},
child: FadeInImage.assetNetwork(
image: 'https://picsart.com/ing',
placeholder: appLogo,
fit: BoxFit.contain,
placeholderFit: BoxFit.contain,
width: 100,
height: 100,
imageErrorBuilder: (_, __, ___) {
return Image.asset(appLogo);
},
),
),
),
),
),
Expand All @@ -43,17 +67,6 @@ class DashboardSliverAppBar extends StatelessWidget {
titlePadding:
const EdgeInsetsDirectional.only(start: 16, bottom: 16),
),
actions: [
IconButton(
onPressed: () {
AuthRepository.instance.logout();
},
icon: Icon(
Icons.power_settings_new,
color: Theme.of(context).colorScheme.error,
),
)
],
leading: null,
automaticallyImplyLeading: false,
);
Expand Down
85 changes: 85 additions & 0 deletions lib/src/features/profile/screen/profile/profile_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import 'package:courses_app/src/constants/images.dart';
import 'package:courses_app/src/widgets/common/FilledCard.dart';
import 'package:flutter/material.dart';

import 'widgets/profile_network_image.dart';

class ProfileScreen extends StatelessWidget {
const ProfileScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Profile'),
),
body: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
ProfileNetworkImage(
onTap: () {},
profileImageUrl:
'https://avatars.githubusercontent.com/u/74584143?v=4',
),
const SizedBox(
height: 16.0,
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'Ravindra Nag',
style: Theme.of(context).textTheme.headlineMedium,
),
const Text('[email protected]'),
const SizedBox(
height: 16.0,
),
FilledButton(
onPressed: () {},
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(Icons.edit),
SizedBox(
width: 8.0,
),
Text('Edit profile'),
],
),
)
],
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 20.0),
child: Divider(),
),
FilledButton.tonal(
onPressed: () {},
style: FilledButton.styleFrom(
padding: const EdgeInsets.symmetric(
vertical: 16.0,
horizontal: 20.0,
),
backgroundColor: Theme.of(context).colorScheme.errorContainer,
foregroundColor: Theme.of(context).colorScheme.error,
),
child: Row(
children: const [
Icon(Icons.logout),
SizedBox(
width: 10.0,
),
Text('Logout')
],
),
)
],
),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:courses_app/src/constants/images.dart';
import 'package:flutter/material.dart';

class ProfileNetworkImage extends StatelessWidget {
const ProfileNetworkImage({
super.key,
required this.profileImageUrl,
this.onTap
});

final String profileImageUrl;
final VoidCallback? onTap;

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.outline,
width: 2,
),
borderRadius: BorderRadius.circular(100),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: InkResponse(
radius: 60,
onTap: onTap,
child: FadeInImage(
image: NetworkImage(profileImageUrl),
placeholder: const AssetImage(appLogo),
fit: BoxFit.cover,
width: 100,
height: 100,
imageErrorBuilder: (_, __, ___) {
return Image.asset(appLogo);
},
),
),
),
);
}
}
3 changes: 2 additions & 1 deletion lib/src/repository/auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class AuthRepository extends GetxController {

Future<void> createUserWithEmailAndPassword(String email, String password) async {
try {
await _auth.createUserWithEmailAndPassword(email: email, password: password);
final userCred = await _auth.createUserWithEmailAndPassword(email: email, password: password);

if(firebaseUser.value != null) {
Get.offAll(() => const DashboardScreen());
}
Expand Down
24 changes: 24 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.1"
cloud_firestore:
dependency: "direct main"
description:
name: cloud_firestore
sha256: f5431cf41ab5c5e9c64e03ac2af103e10be22bf89020f394130c04b81add0010
url: "https://pub.dev"
source: hosted
version: "4.5.1"
cloud_firestore_platform_interface:
dependency: transitive
description:
name: cloud_firestore_platform_interface
sha256: "29349a0687bc31290ab81d1de2b1cdadb40d0ea3ab30d247323c6c5be0d4c6fc"
url: "https://pub.dev"
source: hosted
version: "5.12.0"
cloud_firestore_web:
dependency: transitive
description:
name: cloud_firestore_web
sha256: "228f1944fb3c61ddf5de3647ec5b6ed88d6aacb0a4d485ef597c1211fe98ef8b"
url: "https://pub.dev"
source: hosted
version: "3.4.1"
collection:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies:
firebase_core: ^2.9.0
firebase_auth: ^4.4.1
get: ^4.6.5
cloud_firestore: ^4.5.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit b7c953f

Please sign in to comment.