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

Fram 2 #1

Open
wants to merge 11 commits 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
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {
applicationId "com.example.crudapp"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.crudapp">
<application
android:label="Cruder"
android:label="Notily"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
5 changes: 3 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Feb 03 11:42:05 IST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
zipStoreBase=GRADLE_USER_HOME
Binary file added assets/Images/bot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Images/profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added flutter_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions lib/BackEnd/UserData.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'dart:developer';
import 'package:cloud_firestore/cloud_firestore.dart';
import '../Modal/Response.dart';
import 'models.dart';

final FirebaseFirestore store = FirebaseFirestore.instance;
final CollectionReference reference = store.collection("User");

class UserData {
static userdata(String uid) async {
UserModel d = UserModel(uid: uid);
// log(uid);
try {
await store.collection("User").doc(uid).set(d.toMap());
} catch (e) {
log(e.toString());
}
// log("Done");
}

static profile(UserModel data, String uid) async {
Response r = Response();

DocumentReference documentReference = reference.doc(uid);
await documentReference
.set(data.toMap())
.whenComplete(() => {
r.code = 200,
r.msg = "Record Stored successfully !!",
})
.catchError((e) {
r.code = 500;
r.msg = e.message;
log("${r.msg}");
});
return r;
}

static Future<UserModel?> fetchUser(String uid) async {
try {
DocumentSnapshot<Object?> value = await reference.doc(uid).get();
return UserModel.fromMap(value.data() as Map<String, dynamic>);
} catch (e) {
log(e.toString());
return null;
}
}
}
99 changes: 99 additions & 0 deletions lib/BackEnd/models.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:convert';
import 'package:flutter/foundation.dart';

class UserModel {
final String uid;
String? name;
String? mail;
String? number;
String? dob;
List<Map<String, dynamic>>? notes;

UserModel({
required this.uid,
this.name,
this.mail,
this.number,
this.dob,
this.notes,
});

UserModel copyWith({
String? uid,
String? name,
String? mail,
String? number,
String? dob,
List<Map<String, dynamic>>? notes,
}) {
return UserModel(
uid: uid ?? this.uid,
name: name ?? this.name,
mail: mail ?? this.mail,
number: number ?? this.number,
dob: dob ?? this.dob,
notes: notes ?? this.notes,
);
}

Map<String, dynamic> toMap() {
return <String, dynamic>{
'uid': uid,
'name': name,
'mail': mail,
'number': number,
'dob': dob,
'notes': notes,
};
}

factory UserModel.fromMap(Map<String, dynamic> map) {
return UserModel(
uid: map['uid'] as String,
name: map['name'] != null ? map['name'] as String : null,
mail: map['mail'] != null ? map['mail'] as String : null,
number: map['number'] != null ? map['number'] as String : null,
dob: map['dob'] != null ? map['dob'] as String : null,
notes: map['notes'] != null
? List<Map<String, dynamic>>.from(
(map['notes'] as List<dynamic>).map<Map<String, dynamic>?>(
(x) => x,
),
)
: null,
);
}

String toJson() => json.encode(toMap());

factory UserModel.fromJson(String source) =>
UserModel.fromMap(json.decode(source) as Map<String, dynamic>);

@override
String toString() {
return 'UserModel(uid: $uid, name: $name, mail: $mail, number: $number, dob: $dob, notes: $notes)';
}

@override
bool operator ==(covariant UserModel other) {
if (identical(this, other)) return true;

return other.uid == uid &&
other.name == name &&
other.mail == mail &&
other.number == number &&
other.dob == dob &&
listEquals(other.notes, notes);
}

@override
int get hashCode {
return uid.hashCode ^
name.hashCode ^
mail.hashCode ^
number.hashCode ^
dob.hashCode ^
notes.hashCode;
}
}
10 changes: 10 additions & 0 deletions lib/Drawer/Drawer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';

class Drawer extends StatelessWidget {
const Drawer({super.key});

@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
66 changes: 66 additions & 0 deletions lib/Drawer/DrawerHeader.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// ignore: file_names
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import '../BackEnd/UserData.dart';
import '../BackEnd/models.dart';

class Drawerheader extends StatefulWidget {
const Drawerheader({super.key});

@override
State<Drawerheader> createState() => _DrawerHeaderState();
}

class _DrawerHeaderState extends State<Drawerheader> {
TextEditingController name = TextEditingController();
TextEditingController email = TextEditingController();
@override
void initState() {
// dob.text = " ";
super.initState();
fetchData();
}

fetchData() async {
UserModel? d =
await UserData.fetchUser(FirebaseAuth.instance.currentUser!.uid);
// if (d != null) {
setState(() {
name.text = d?.name ?? " ";
// email.text = d.mail ?? "";
});
// } else {}
}

@override
Widget build(BuildContext context) {
return Container(
color: Colors.blue.shade300,
height: 200,
width: double.infinity,
padding: const EdgeInsets.only(top: 20.0),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Container(
margin: const EdgeInsets.only(bottom: 10),
height: 70,
decoration: const BoxDecoration(
shape: BoxShape.circle,
image:
DecorationImage(image: AssetImage("assets/Images/profile.png")),
),
),
Text(name.text.isEmpty ? " " : name.text,
// FirebaseAuth.instance.currentUser!.email.toString(),
style: const TextStyle(
fontSize: 20,
color: Colors.white,
)),
Text(
// email.text.isEmpty ? "Enter Your Email" : email.text,
FirebaseAuth.instance.currentUser!.email.toString(),
style: TextStyle(color: Colors.grey.shade300, fontSize: 10),
)
]),
);
}
}
75 changes: 75 additions & 0 deletions lib/Drawer/Itemheader.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:crudapp/Pages/ChatScreen.dart';
import 'package:crudapp/Pages/Profile.dart';
import 'package:crudapp/main.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';

class Itemheader extends StatefulWidget {
const Itemheader({super.key});

@override
State<Itemheader> createState() => _ItemheaderState();
}

class _ItemheaderState extends State<Itemheader> {
@override
Widget build(BuildContext context) {
return Material(
child: Padding(
padding: const EdgeInsets.only(top: 25),
child: Column(
children: [
ListTile(
leading: const Icon(
Icons.dashboard_outlined,
size: 25,
color: Colors.black,
),
title: Text(
"Profile",
style: TextStyle(fontSize: 20, color: Colors.grey.shade500),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const Profile(),
));
},
),
ListTile(
leading: const Icon(
Icons.search_outlined,
size: 25,
color: Colors.black,
),
title:const Text(
"Search",
style: TextStyle(fontSize: 20, color: Colors.grey),
),
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => const ChatScreen()));
}),
ListTile(
leading: const Icon(
Icons.logout_rounded,
size: 25,
color: Colors.black,
),
title: Text(
"Log Out",
style: TextStyle(fontSize: 20, color: Colors.grey.shade500),
),
onTap: () {
FirebaseAuth.instance.signOut().then((value) => Navigator.push(
context,
MaterialPageRoute(builder: (context) => const MainPage())));
},
),
],
),
),
);
}
}
Loading