-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from this-is-mjk/main
login and register done, along with some required changes in server, and some more file structuring
- Loading branch information
Showing
18 changed files
with
698 additions
and
590 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import 'package:attendance_app/services/store.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class ProfileCard extends StatelessWidget { | ||
ProfileCard({ | ||
super.key, | ||
}); | ||
final TokenService _tokenService = TokenService(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return FutureBuilder<Map<String, dynamic>?>( | ||
future: _tokenService.getDecodedToken(), | ||
builder: (context, snapshot) { | ||
if (snapshot.connectionState == ConnectionState.waiting) { | ||
return const Center(child: CircularProgressIndicator()); | ||
} | ||
if (snapshot.hasError || snapshot.data == null) { | ||
return const Center(child: Text("Failed to load profile")); | ||
} | ||
final decodedToken = snapshot.data!; | ||
final String name = decodedToken['user']['name'] ?? 'Unknown'; | ||
final String role = decodedToken['user']['position'] ?? 'User'; | ||
final String imageUrl = decodedToken['user']['imageUrl'] ?? ''; | ||
|
||
return SizedBox( | ||
// width: double.infinity, | ||
child: ElevatedButton( | ||
style: ElevatedButton.styleFrom( | ||
backgroundColor: Colors.white, | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(10.0), | ||
), | ||
elevation: 10.0, | ||
), | ||
onPressed: () { | ||
Navigator.pushNamed(context, '/profile'); | ||
}, | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 10.0), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
const SizedBox(height: 8.0), | ||
CircleAvatar( | ||
radius: 50.0, | ||
backgroundImage: imageUrl.isNotEmpty | ||
? NetworkImage(imageUrl) | ||
: const AssetImage('assets/profileimg.png') | ||
as ImageProvider, | ||
), | ||
const SizedBox(height: 8.0), | ||
Text( | ||
name, | ||
style: const TextStyle( | ||
fontSize: 20.0, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
Text( | ||
role, | ||
style: TextStyle( | ||
fontSize: 16.0, | ||
color: Colors.grey[800], | ||
letterSpacing: 2.0, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,53 +1,80 @@ | ||
import 'package:attendance_app/screens/userdashboard.dart'; | ||
import 'package:attendance_app/screens/adminDashboard.dart'; | ||
import 'package:attendance_app/screens/user_dashboard.dart'; | ||
import 'package:attendance_app/screens/admin_dashboard.dart'; | ||
import 'package:attendance_app/screens/user_events.dart'; | ||
import 'package:attendance_app/screens/capturepic.dart'; | ||
import 'package:attendance_app/screens/capture_pic.dart'; | ||
import 'package:attendance_app/screens/login_page.dart'; | ||
// import 'package:attendance_app/screens/attendace_history.dart'; | ||
import 'package:attendance_app/screens/registration.dart'; | ||
import 'package:attendance_app/screens/profile.dart'; | ||
import 'package:attendance_app/screens/locationpage.dart'; | ||
import 'package:attendance_app/screens/location_page.dart'; | ||
import 'package:attendance_app/services/store.dart'; | ||
import 'package:attendance_app/src/shared/data.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'dart:async'; | ||
|
||
import 'package:get/get.dart'; | ||
import 'dart:async'; | ||
|
||
Future<void> main() async { | ||
fillData(); | ||
// how to capture the image and upload it to the server is remaining | ||
// also all the api calls are remaining | ||
runApp(const MaterialApp(home: MyApp())); | ||
runApp(const MyApp()); // Use MyApp directly | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
// final List<CameraDescription> cameras; | ||
|
||
class MyApp extends StatefulWidget { | ||
const MyApp({super.key}); | ||
|
||
@override | ||
State<MyApp> createState() => _MyAppState(); | ||
} | ||
|
||
class _MyAppState extends State<MyApp> { | ||
final TokenService _tokenService = TokenService(); | ||
String initialRoute = "/login"; // Default route to '/login' | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_checkTokenStatus(); | ||
} | ||
|
||
Future<void> _checkTokenStatus() async { | ||
bool isValid = await _tokenService.isTokenValid(); | ||
if (isValid) { | ||
// Token is valid, check the role | ||
Map<String, dynamic>? decodedToken = | ||
await _tokenService.getDecodedToken(); | ||
if (decodedToken != null) { | ||
String role = decodedToken['user']['role'] ?? ''; | ||
setState(() { | ||
initialRoute = role == 'ADMIN' ? '/adminDashboard' : '/userDashboard'; | ||
// Navigate to the role-specific page | ||
Get.offNamed(initialRoute); // Navigate here | ||
}); | ||
} | ||
} else { | ||
// Token is not valid or doesn't exist, navigate to login | ||
Get.offNamed('/login'); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
const String initialRoute = "/login"; | ||
return GetMaterialApp( | ||
// Use GetMaterialApp here | ||
title: 'Attendance App', | ||
debugShowCheckedModeBanner: false, | ||
theme: ThemeData( | ||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.white), | ||
useMaterial3: true, | ||
), | ||
initialRoute: initialRoute, | ||
routes: { | ||
'/login': (context) => const LoginPage(), | ||
// '/history': (context) => const History(), // made it as user event page | ||
'/userDashboard': (context) => const userDashboard(), | ||
'/adminDashboard': (context) => const adminDashboard(), | ||
'/userDashboard': (context) => const UserDashboard(), | ||
'/adminDashboard': (context) => const AdminDashboard(), | ||
'/usereventpage': (context) => const userEvents(), | ||
'/register': (context) => const RegistrationPage(), | ||
'/picture': (context) => const CapturePicPage(), | ||
'/profile': (context) => const ProfileScreen(), | ||
'/location': (context) => const LocationPage(), | ||
|
||
|
||
}, | ||
initialRoute: initialRoute, // Default, but overridden by dynamic routing | ||
); | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.