Skip to content

Commit

Permalink
Merge pull request #32 from this-is-mjk/main
Browse files Browse the repository at this point in the history
login and register done, along with some required changes in server, and some more file structuring
  • Loading branch information
its-me-yps authored Oct 11, 2024
2 parents 738df0d + 8ec8934 commit a677b38
Show file tree
Hide file tree
Showing 18 changed files with 698 additions and 590 deletions.
19 changes: 3 additions & 16 deletions lib/screens/drawer.dart → lib/components/drawer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:attendance_app/components/navbar_item.dart';
import 'package:attendance_app/screens/login_page.dart';
// import 'package:attendance_app/screens/profile.dart';
import 'package:attendance_app/services/logout.dart';
import 'package:flutter/material.dart';
import 'package:line_awesome_flutter/line_awesome_flutter.dart';

Expand Down Expand Up @@ -55,13 +54,6 @@ class DrawerItems extends StatelessWidget {
icon: LineAwesomeIcons.user,
text: 'Profile',
onTap: () {
// Navigator.pop(context);
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) =>
// ProfileScreen()), // replace ProfileScreen with your destination widget
// );
Navigator.pushNamed(context, '/profile');
},
textStyle: theme.textTheme.bodyLarge
Expand Down Expand Up @@ -90,13 +82,8 @@ class DrawerItems extends StatelessWidget {
NavbarItem(
icon: Icons.login_sharp,
text: 'Log Out',
onTap: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const LoginPage(),
),
);
onTap: () async {
await LogoutService().logoutAndNavigateToLogin(context);
},
textStyle: theme.textTheme.bodyLarge
?.copyWith(color: theme.colorScheme.onSurface),
Expand Down
76 changes: 76 additions & 0 deletions lib/components/profile_card.dart
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,
),
),
],
),
),
),
);
},
);
}
}
67 changes: 47 additions & 20 deletions lib/main.dart
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
);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import 'dart:math';
import 'package:attendance_app/components/profile_card.dart';
import 'package:attendance_app/services/logout.dart';
import 'package:flutter/material.dart';
import 'package:attendance_app/screens/drawer.dart';
import 'package:attendance_app/components/drawer.dart';
import 'package:attendance_app/components/background_painter.dart';
import 'package:attendance_app/components/calendar.dart';

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

@override
State<adminDashboard> createState() => _Dashboard1State();
State<AdminDashboard> createState() => _Dashboard1State();
}

class _Dashboard1State extends State<adminDashboard> {
class _Dashboard1State extends State<AdminDashboard> {
@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -22,9 +24,8 @@ class _Dashboard1State extends State<adminDashboard> {
IconButton(
icon: const Icon(Icons.logout),
tooltip: 'Logout',
onPressed: () {
// logoutlogic
Navigator.pop(context);
onPressed: () async {
await LogoutService().logoutAndNavigateToLogin(context);
},
),
],
Expand All @@ -41,7 +42,7 @@ class _Dashboard1State extends State<adminDashboard> {
child: SingleChildScrollView(
child: Column(
children: [
const ProfileCard(name: "Ram Krishna", role: "Senior Officer"),
ProfileCard(),
const SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -68,7 +69,7 @@ class _Dashboard1State extends State<adminDashboard> {
width: min(double.infinity, 400),
child: ElevatedButton(
onPressed: () {
Navigator.pushNamed(context, '/history');
Navigator.pushNamed(context, '/usereventpage');
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
Expand All @@ -90,66 +91,6 @@ class _Dashboard1State extends State<adminDashboard> {
}
}

class ProfileCard extends StatelessWidget {
const ProfileCard({
super.key,
required this.name,
required this.role,
});

final String name;
final String role;

@override
Widget build(BuildContext context) {
return SizedBox(
width: min(double.infinity, 400),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
elevation: 10.0,
),
onPressed: () {
Navigator.pushNamed(context, '/profile');
},
// padding: const EdgeInsets.all(4.0),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 8.0),
const CircleAvatar(
radius: 50.0,
backgroundImage: AssetImage('assets/profileimg.png'),
),
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,
),
),
],
),
),
),
);
}
}

class ActionButtons extends StatelessWidget {
final String label;
final IconData icon;
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a677b38

Please sign in to comment.