Browse Source

profile page with userdata

David Sokol Zelazko 3 năm trước cách đây
mục cha
commit
80ac91bdc5

+ 5 - 3
app/lib/Services/AuthServiec.dart

@@ -5,14 +5,16 @@ class AuthenticationServices {
   final FirebaseAuth _auth = FirebaseAuth.instance;
 
   //Register a user
-  Future createNewUser(String name, String email, String password) async {
+  Future createNewUser(String address, bool anonymous, String birth,
+      String name, String email, String password, String phone, String sharedID,
+      String surname) async {
     try {
       UserCredential result = await _auth.createUserWithEmailAndPassword(
           email: email, password: password);
       User? user = result.user;
       await DatabaseManager().createUserData(
-          "null", true, DateTime.now(), DateTime.now(), DateTime.now(), email, name, 'phoneNumber', 'shared_id', 'surname', 0, DateTime.now(), 'weeklyplace', user!.uid);
-
+          address, anonymous, birth, DateTime.now(), DateTime.now(), email,
+          name, phone, sharedID, surname, 0, DateTime.now(), 'null', user!.uid);
 
       return user;
     } catch (e) {

+ 23 - 6
app/lib/Services/DatabaseManager.dart

@@ -1,15 +1,26 @@
 //import 'package:cloud_firestore/cloud_firestore.dart';
 import 'package:cloud_firestore/cloud_firestore.dart';
+import 'package:flutter/cupertino.dart';
 
 class DatabaseManager {
   final CollectionReference profileList =
   FirebaseFirestore.instance.collection('profileInfo');
 
-  Future<void> createUserData(
-      String address, bool anonymous, DateTime birth_date, DateTime create_date,
-      DateTime lastChallengeDate, String mail, String name, String phoneNumber,
-      String shared_id, String surname, int totalpoints, DateTime updated_date,
-      String weeklyplace, String uid) async {
+  Future<void> createUserData(String address,
+      bool anonymous,
+      String birth_date,
+      DateTime create_date,
+      DateTime lastChallengeDate,
+      String mail,
+      String name,
+      String phoneNumber,
+      String shared_id,
+      String surname,
+      int totalpoints,
+      DateTime updated_date,
+      String weeklyplace,
+      String uid) async {
+    print('----------- ' + uid);
     return await profileList.doc(uid).set({
       'address': address,
       'anonymous': anonymous,
@@ -24,7 +35,13 @@ class DatabaseManager {
       'total_points': totalpoints,
       'updated_date': updated_date,
       'weekly_place': weeklyplace,
-
     });
   }
+
+  Future getusersList(String id) async {
+  }
 }
+//  FirebaseFirestore.instance.collection('profileInfo').doc(arguments['id'])
+//         .get().then((DocumentSnapshot) =>
+//         print('____'+DocumentSnapshot.data().toString())
+//     );

+ 8 - 3
app/lib/SignupPage.dart

@@ -1,6 +1,8 @@
 import 'package:flutter/material.dart';
 import 'package:physigo/Services/AuthServiec.dart';
 
+import 'Services/DatabaseManager.dart';
+
 //Fields..
 TextEditingController _name = TextEditingController();
 TextEditingController _surname = TextEditingController();
@@ -16,6 +18,7 @@ String? _dateString;
 
 final AuthenticationServices _auth = AuthenticationServices();
 
+
 class SignupPage extends StatefulWidget {
   const SignupPage({Key? key}) : super(key: key);
 
@@ -136,7 +139,7 @@ class _SignupForm1 extends State<SignupForm1> {
                     .then((date) {
                   setState(() {
                     _dateTime = date!;
-                    _dateString = "${date.day}/${date.month}/${date.year}";
+                    _dateString = "${date.day}-${date.month}-${date.year}";
                   });
                 });
               },
@@ -286,7 +289,8 @@ class _SignupForm3 extends State<SignupForm3> {
                   print(e.toString());
                 }
               },
-              child: const Text('Finish Register'))
+              child: const Text('Finish Register')),
+
         ]),
       )),
     );
@@ -294,7 +298,8 @@ class _SignupForm3 extends State<SignupForm3> {
 
   void createUser() async {
     dynamic result =
-        await _auth.createNewUser(_name.text, _mail.text, _passwd.text);
+        await _auth.createNewUser(_address.text, anonymous, _dateString.toString(), _name.text, _mail.text, _passwd.text,
+            _phoneNumber.text, _username.text, _surname.text);
     if (result == null) {
       print('mail not valid');
     } else {

+ 40 - 42
app/lib/logIn.dart

@@ -1,5 +1,4 @@
 import 'package:flutter/material.dart';
-
 import 'Services/AuthServiec.dart';
 
 class LogIn extends StatefulWidget {
@@ -16,7 +15,6 @@ class _LogIn extends State<LogIn> {
   TextEditingController _passwd = TextEditingController();
   final AuthenticationServices _auth = AuthenticationServices();
 
-
   @override
   Widget build(BuildContext context) {
     return Scaffold(
@@ -25,55 +23,55 @@ class _LogIn extends State<LogIn> {
       ),
       body: Center(
           child: SizedBox(
-            width: 300,
-            child: Column(children: <Widget>[
-              const SizedBox(height: 30),
-              Text(
-                'Welcome back!',
-                style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
-              ),
-              const SizedBox(height: 30),
-              Image.asset(
-                'assets/hello.png',
-                width: 150,
-              ),
-              const SizedBox(height: 30),
-              TextFormField(
-                controller: _email,
-                decoration: InputDecoration(
-                  hintText: 'Mail or mobile phone',
-                ),
-              ),
-              const SizedBox(height: 10),
-              TextFormField(
-                controller: _passwd,
-                decoration: InputDecoration(
-                  hintText: 'Password',
-                ),
-              ),
-              const SizedBox(height: 10),
-              ElevatedButton(
-                onPressed: () {
-                  signInUser();
-                },
-                child: const Text('Log In'),
-              ),
-
-
-            ]),
-          )),
+        width: 300,
+        child: Column(children: <Widget>[
+          const SizedBox(height: 30),
+          Text(
+            'Welcome back!',
+            style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
+          ),
+          const SizedBox(height: 30),
+          Image.asset(
+            'assets/hello.png',
+            width: 150,
+          ),
+          const SizedBox(height: 30),
+          TextFormField(
+            controller: _email,
+            decoration: InputDecoration(
+              hintText: 'Mail or mobile phone',
+            ),
+          ),
+          const SizedBox(height: 10),
+          TextFormField(
+            controller: _passwd,
+            decoration: InputDecoration(
+              hintText: 'Password',
+            ),
+          ),
+          const SizedBox(height: 10),
+          ElevatedButton(
+            onPressed: () {
+              signInUser();
+            },
+            child: const Text('Log In'),
+          ),
+        ]),
+      )),
     );
   }
 
   void signInUser() async {
     dynamic authResult = await _auth.loginUser(_email.text, _passwd.text);
-    if (authResult==null) {
+    if (authResult == null) {
       print("log in error");
     } else {
       _email.clear();
       _passwd.clear();
       print("Succesful login ");
-      Navigator.pushNamed(context, '/mainPage');
+      Navigator.pushNamed(context, '/mainPage',
+        arguments: {'uid': authResult.uid},
+      );
     }
   }
-}
+}

+ 2 - 0
app/lib/main.dart

@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
 import 'firebase_options.dart';
 import 'push_notifications_initializer.dart';
 import 'package:physigo/logIn.dart';
+import 'package:physigo/profilePage.dart';
 import 'package:physigo/SignupPage.dart';
 import 'package:physigo/mainPage.dart';
 import 'package:physigo/welcomeScreen.dart';
@@ -34,6 +35,7 @@ class PhysiGo extends StatelessWidget {
         //'/register2': (context) => RegisterScreen2(title: ''),
         //'/register3': (context) => RegisterScreen3(title: ''),
         '/login': (context) => LogIn(title: ''),
+        '/profilePage': (context) => ProfilePage(title: '',),
         '/mainPage': (context) => MainPage()
       },
       //home: const MyHomePage(title: 'Flutter Demo Home Page'),

+ 22 - 5
app/lib/mainPage.dart

@@ -10,14 +10,31 @@ class _MainPage extends State<MainPage> {
 
   @override
   Widget build(BuildContext context) {
+    final arguments = (ModalRoute.of(context)?.settings.arguments ?? <String, dynamic>{}) as Map;
+    final String id = arguments['uid'];
+    print(id);
+
     return Scaffold(
-      floatingActionButton: FloatingActionButton(
-        onPressed: () {
+      appBar: AppBar(
+
+        title: const Text('Welcome Back!'),
+        leading: GestureDetector(
+          onTap: () {
+            print('going to profile page');
+            Navigator.pushNamed(context, '/profilePage',
+              arguments: {'id': id},
+            );
+            },
+          child: Icon(
+            Icons.account_circle_rounded,  // add custom icons also
+          ),
+        ),
+      ),
+      body: Center(
+        child: Column(
+        ),
 
-        },
-        child: Icon(Icons.add),
       ),
-      body: Center(child: Text("hello")),
     );
   }
 }

+ 101 - 0
app/lib/profilePage.dart

@@ -0,0 +1,101 @@
+import 'package:cloud_firestore/cloud_firestore.dart';
+import 'package:flutter/material.dart';
+
+class ProfilePage extends StatefulWidget {
+  const ProfilePage({Key? key, required this.title}) : super(key: key);
+  final String title;
+
+  @override
+  //_RegisterScreen createState() => _RegisterScreen();
+  State<ProfilePage> createState() => _ProfilePage();
+}
+
+class _ProfilePage extends State<ProfilePage> {
+  String name = '', surname = '', birth_date = '', mail = '', shared_id = '',
+      phone_number = '', anonymous = '', address = '';
+
+  @override
+  Widget build(BuildContext context) {
+    final arguments = (ModalRoute.of(context)?.settings.arguments ??
+        <String, dynamic>{}) as Map;
+    print('******' + arguments['id']);
+
+    //getting info of the user one by one
+    FirebaseFirestore.instance.collection('profileInfo').doc(arguments['id'])
+        .get().then((DocumentSnapshot) {
+      name = DocumentSnapshot.get('name').toString();
+    });
+    FirebaseFirestore.instance.collection('profileInfo').doc(arguments['id'])
+        .get().then((DocumentSnapshot) {
+      surname = DocumentSnapshot.get('surname').toString();
+    });
+    FirebaseFirestore.instance.collection('profileInfo').doc(arguments['id'])
+        .get().then((DocumentSnapshot) {
+      birth_date = DocumentSnapshot.get('birth_date').toString();
+    });
+    FirebaseFirestore.instance.collection('profileInfo').doc(arguments['id'])
+        .get().then((DocumentSnapshot) {
+      mail = DocumentSnapshot.get('mail').toString();
+    });
+    FirebaseFirestore.instance.collection('profileInfo').doc(arguments['id'])
+        .get().then((DocumentSnapshot) {
+      shared_id = DocumentSnapshot.get('shared_id').toString();
+    });
+    FirebaseFirestore.instance.collection('profileInfo').doc(arguments['id'])
+        .get().then((DocumentSnapshot) {
+      phone_number = DocumentSnapshot.get('phone_number').toString();
+    });
+    FirebaseFirestore.instance.collection('profileInfo').doc(arguments['id'])
+        .get().then((DocumentSnapshot) {
+      anonymous = DocumentSnapshot.get('anonymous').toString();
+    });
+    FirebaseFirestore.instance.collection('profileInfo').doc(arguments['id'])
+        .get().then((DocumentSnapshot) {
+      address = DocumentSnapshot.get('address').toString();
+    });
+
+    return Scaffold(
+      appBar: AppBar(title: const Text('Profile Page')),
+      body: Center(
+        child: SizedBox(
+          width: 300,
+          child: Column(
+            children: [
+              const SizedBox(height: 30),
+              Text(
+                'Personal Information',
+                style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
+              ),
+              const SizedBox(height: 30),
+              Image.asset(
+                'assets/user.png',
+                width: 150,
+              ),
+              const SizedBox(height: 30),
+              Text('Name: ' + name + ' ' + surname),
+              const SizedBox(height: 10),
+              Text('Birth Date: ' + birth_date),
+              const SizedBox(height: 10),
+              Text('Username: ' + shared_id),
+              const SizedBox(height: 10),
+              Text('Mail: ' + mail),
+              const SizedBox(height: 10),
+              Text('Phone: ' + phone_number),
+              const SizedBox(height: 10),
+              Text('Address: ' + address),
+              const SizedBox(height: 10),
+              Text('Anonymous: ' + anonymous),
+              const SizedBox(height: 30),
+              ElevatedButton(
+                onPressed: () {
+                  setState(() {});
+                },
+                child: const Text('Refresh'),
+              ),
+            ],
+          ),
+        ),
+      ),
+    );
+  }
+}