fish 1 year ago
parent
commit
e652294ec1

+ 3 - 10
lib/main.dart

@@ -5,30 +5,23 @@ import 'package:putra_go/services/auth.dart';
 import 'models/user.dart';
 import 'screens/passenger/userMain.dart';
 
-
 void main() async {
-  WidgetsFlutterBinding.ensureInitialized(); // ensure Flutter binding initialise
-  await Firebase.initializeApp(); // initialise Firebase
+  WidgetsFlutterBinding.ensureInitialized();
+  await Firebase.initializeApp();
   runApp(MyApp());
 }
 
 class MyApp extends StatelessWidget {
-
   Widget build(BuildContext context) {
     //add stream Provider
     return StreamProvider<User?>.value(
       value: AuthService().user,
       initialData: null,
-
       child: const MaterialApp(
-        //remove Debug Banner for all
         debugShowCheckedModeBanner: false,
         title: 'PutraGo',
-
-        home: userMain(),
+        home: HomePage(),
       ),
     );
   }
-
 }
-

+ 1 - 1
lib/models/order.dart

@@ -32,7 +32,7 @@ List<Order> orders = [
 
   Order(
     name: 'Aqil',
-    email:'2323@upm.com',
+    email: '2323@upm.com',
     time: '24-1-2 08:40 AM',
     route: 'Within UPM',
     start: 'K17',

+ 4 - 8
lib/models/user.dart

@@ -1,13 +1,10 @@
-
-
-enum Roles {passenger, driver, admin}
+enum Roles { passenger, driver, admin }
 
 class User {
-
   final String uid;
-  final String email ;
+  final String email;
   final String phoneNumber;
-  final String icNumber ;
+  final String icNumber;
   final String password;
   // text about car information
   // final String carID;
@@ -28,5 +25,4 @@ class User {
     // required this.carBrand,
     // required this.carColor
   });
-
-}
+}

+ 1 - 1
lib/screens/driver/driverMain.dart

@@ -130,7 +130,7 @@ class _driverMainState extends State<driverMain> {
                       // Handle login as a driver button press
                       Navigator.push(
                         context,
-                        MaterialPageRoute(builder: (context) => userMain()),
+                          MaterialPageRoute(builder: (context) => HomePage()),
                       );
                     },
                     child: const Text(

+ 1 - 1
lib/screens/passenger/authenticate/userLogin.dart

@@ -35,7 +35,7 @@ class _userLoginState extends State<userLogin> {
           onPressed: () {
             Navigator.push(
               context,
-              MaterialPageRoute(builder: (context) => const userMain()),
+                MaterialPageRoute(builder: (context) => const HomePage()),
             );
           },
         ),

+ 1 - 1
lib/screens/passenger/userHome/userCustomizedOrder.dart

@@ -69,7 +69,7 @@ class _CustomOrderPageState extends State<userCustomizedOrder> {
           onPressed: () {
             Navigator.push(
               context,
-              MaterialPageRoute(builder: (context) => userMain()),
+                MaterialPageRoute(builder: (context) => HomePage()),
             );
           },
         ),

+ 1 - 1
lib/screens/passenger/userHome/userOrderCancelled.dart

@@ -53,7 +53,7 @@ class userOrderCancelled extends StatelessWidget {
                     // Handle Next button press
                     Navigator.push(
                       context,
-                      MaterialPageRoute(builder: (context) => userMain()),
+                      MaterialPageRoute(builder: (context) => HomePage()),
                     );
                   },
                   child: const Text(

+ 2 - 2
lib/screens/passenger/userMain.dart

@@ -3,8 +3,8 @@ import '../driver/driverMain.dart';
 import 'authenticate/userLogin.dart';
 import 'authenticate/userRegister.dart';
 
-class userMain extends StatelessWidget {
-  const userMain({Key? key}) : super(key: key);
+class HomePage extends StatelessWidget {
+  const HomePage({Key? key}) : super(key: key);
 
   @override
   Widget build(BuildContext context) {

+ 2 - 4
lib/screens/userWapper.dart

@@ -10,16 +10,14 @@ class userWapper extends StatelessWidget {
 
   @override
   Widget build(BuildContext context) {
-
     final user = Provider.of<User?>(context);
     print(user);
 
     // return either the Home or Authenticate widget
-    if (user == null){
+    if (user == null) {
       return Authenticate();
     } else {
       return userCustomizedOrder();
     }
-
   }
-}
+}

+ 24 - 24
lib/services/auth.dart

@@ -6,17 +6,18 @@ class AuthService {
 
 // Convert a Firebase User to a custom User
   User? _userFromFirebase(firebase_auth.User? user) {
-    return user != null ?
-    User(
-        uid: user.uid,
-        email: '',
-        phoneNumber: '',
-        icNumber: '',
-        password: '',
-        // carID: '',
-        // carBrand: '',
-        // carColor: ''
-    ) : null;
+    return user != null
+        ? User(
+            uid: user.uid,
+            email: '',
+            phoneNumber: '',
+            icNumber: '',
+            password: '',
+            // carID: '',
+            // carBrand: '',
+            // carColor: ''
+          )
+        : null;
   }
 
 // Auth change user stream
@@ -27,8 +28,7 @@ class AuthService {
 // Sign in anonymously
   Future<User?> signInAnonymously() async {
     try {
-      firebase_auth.UserCredential authResult = await
-      _auth.signInAnonymously();
+      firebase_auth.UserCredential authResult = await _auth.signInAnonymously();
       User? user = _userFromFirebase(authResult.user);
       if (user != null) {
         print('User signed in anonymously with UID: ${user.uid}');
@@ -41,11 +41,11 @@ class AuthService {
   }
 
 // Sign in with email and password
-  Future<User?> signInWithEmailAndPassword(String email, String password) async
-  {
+  Future<User?> signInWithEmailAndPassword(
+      String email, String password) async {
     try {
-      firebase_auth.UserCredential authResult = await
-      _auth.signInWithEmailAndPassword(
+      firebase_auth.UserCredential authResult =
+          await _auth.signInWithEmailAndPassword(
         email: email,
         password: password,
       );
@@ -57,13 +57,13 @@ class AuthService {
   }
 
 // Register with email and password
-  Future<User?> registerWithEmailAndPassword(String email, String password)
-  async {
+  Future<User?> registerWithEmailAndPassword(
+      String email, String password) async {
     try {
-      firebase_auth.UserCredential authResult = await
-      _auth.createUserWithEmailAndPassword(
-          email: email,
-          password: password,
+      firebase_auth.UserCredential authResult =
+          await _auth.createUserWithEmailAndPassword(
+        email: email,
+        password: password,
       );
       return _userFromFirebase(authResult.user);
     } catch (e) {
@@ -80,4 +80,4 @@ class AuthService {
       print('Error signing out: $e');
     }
   }
-}
+}