drawer profile functionality added

This commit is contained in:
venbaittech 2025-01-07 10:56:50 +05:30
parent 65cf46226c
commit fb68b1aa79
3 changed files with 192 additions and 71 deletions

View File

@ -324,7 +324,7 @@ final GoRouter router = GoRouter(
GoRoute(
path: '/',
builder: (context, state) => LoginRoute(),
//builder: (context, state) => MyHomePage(),
// builder: (context, state) => MyHomePage(),
),
GoRoute(
path: '/login',

View File

@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:pocketbase/pocketbase.dart';
import 'package:share_plus/share_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
class BaseScaffold extends StatelessWidget {
class BaseScaffold extends StatefulWidget {
final Widget body;
final Widget title;
final List<Widget>? actions;
@ -12,9 +15,81 @@ class BaseScaffold extends StatelessWidget {
required this.title,
this.actions,
}) : super(key: key);
// final Widget body;
//
// const BaseScaffold({required this.body});
@override
_BaseScaffoldState createState() => _BaseScaffoldState();
}
class _BaseScaffoldState extends State<BaseScaffold> {
final _pb = PocketBase('https://pb.venbait.in');
String _avatarUrl = '';
dynamic userId;
String? userName;
String? userEmail;
String? userAvatar;
String? role;
@override
void initState() {
super.initState();
_checkUserId();
}
// Method to retrieve userId from SharedPreferences
Future<String?> getUserId() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getString('userId'); // Retrieve the userId
}
// Method to check if userId exists and update state
Future<void> _checkUserId() async {
String? fetchedUserId = await getUserId();
if (fetchedUserId != null && fetchedUserId.isNotEmpty) {
setState(() {
userId = fetchedUserId;
});
//print('NAVUser ID: $userId');
_fetchUserData();
} else {
print('No userId found');
// Handle the case where userId is not available
}
}
Future<void> _fetchUserData() async {
try {
final adminAuth = await _pb.admins
.authWithPassword('pb@venbainfotech.com', 'pb@venbainfotech.com');
final adminToken = adminAuth.token;
//print('adminToken- ${adminToken}');
final userDetailsResponse = await _pb.collection('users').getOne(
userId!,
headers: {
'Authorization': 'Bearer $adminToken',
},
);
print('NAVuserDetails: $userDetailsResponse');
setState(() {
userName = userDetailsResponse.data['username'] ?? '';
userEmail = userDetailsResponse.data['email'] ?? '';
userAvatar = userDetailsResponse.data['avatar'] ?? '';
role = userDetailsResponse.data['role'] ?? '';
String recordId = userId;
String collectionId =
userDetailsResponse.data['collectionId'] ?? '_pb_users_auth_';
if (userAvatar!.isNotEmpty && recordId.isNotEmpty) {
_avatarUrl =
'https://pb.venbait.in/api/files/$collectionId/$recordId/$userAvatar';
} else {
_avatarUrl = ''; // Reset to default or empty
}
});
} catch (e) {
print('Error fetching user details: $e');
}
}
@override
Widget build(BuildContext context) {
@ -22,15 +97,29 @@ class BaseScaffold extends StatelessWidget {
String currentRoute = GoRouterState.of(context).matchedLocation;
double myheight = MediaQuery.of(context).size.height;
double mywidth = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(title: title, actions: [
IconButton(onPressed: () {}, icon: Icon(Icons.toggle_off_outlined)),
]),
appBar: AppBar(
title: widget.title,
actions: [
// IconButton(
// onPressed: () {
// // Share logic here
// print("Share icon pressed");
// Share.share(
// 'Open the app: fcscapp://home\n\n'
// 'If you dont have the app installed, '
// 'visit: http://localhost:65493');
// },
// icon: Icon(Icons.share),
// ),
IconButton(onPressed: () {}, icon: Icon(Icons.toggle_off_outlined)),
],
),
drawer: Drawer(
child: ListView(
children: [
DrawerHeader(
//decoration: BoxDecoration(color: Colors.blue),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
@ -48,18 +137,39 @@ class BaseScaffold extends StatelessWidget {
child: Row(
children: [
SizedBox(
width: mywidth / 8,
child: Image(
image: AssetImage(
'assets/edit_profile/profile.png'))),
width: mywidth / 8,
height: mywidth / 8,
child: ClipOval(
child: _avatarUrl.isNotEmpty
? Image(
image: NetworkImage(_avatarUrl),
fit: BoxFit.cover,
width: double.infinity,
height: double.infinity,
)
: Image(
image: AssetImage(
'assets/edit_profile/profile.png'),
fit: BoxFit.cover,
width: double.infinity,
height: double.infinity,
),
),
//child: Image(image: AssetImage('assets/edit_profile/profile.png'))
),
SizedBox(
width: mywidth / 20,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Mohammad'),
Text('Mohammad@fcsc.com')
// Text(userId ?? 'Loading user...'), // Display userId here
// Text('Mohammad@fcsc.com')
Text(userName ?? 'Loading...'),
Text(
userEmail ?? 'Loading...',
style: TextStyle(fontSize: 12),
),
],
)
],
@ -68,34 +178,45 @@ class BaseScaffold extends StatelessWidget {
],
),
),
if (role != 'admin')
ListTile(
leading: SizedBox(
height: myheight / 15,
width: mywidth / 15,
child: Image(
image: AssetImage('assets/icons/drawer/message.png'))),
title: Text('Feedback'),
onTap: () => context.go('/feedback'),
),
if (role == 'admin')
ListTile(
leading: SizedBox(
height: myheight / 15,
width: mywidth / 15,
child: Image(
image:
AssetImage('assets/icons/drawer/manageuser.png'))),
title: Text('Manage User'),
onTap: () => context.go('/manageuser'),
),
ListTile(
leading: SizedBox(
height: myheight / 15,
width: mywidth / 15,
child: Image(
image: AssetImage('assets/icons/drawer/message.png'))),
title: Text('Feedback'),
onTap: () => context.go('/feedback'),
),
ListTile(
leading: SizedBox(
height: myheight / 15,
width: mywidth / 15,
child: Image(
image: AssetImage('assets/icons/drawer/manageuser.png'))),
title: Text('Manage User'),
onTap: () => context.go('/manageuser'),
),
ListTile(
leading: SizedBox(
height: myheight / 15,
width: mywidth / 15,
child: Image(
image: AssetImage('assets/icons/drawer/book.png'))),
child:
Image(image: AssetImage('assets/icons/drawer/book.png'))),
title: Text('User Guide'),
onTap: () => context.go('/user-guide'),
),
ListTile(
leading: SizedBox(
height: myheight / 15,
width: mywidth / 15,
child: Image(
image: AssetImage('assets/icons/drawer/logout.png'))),
title: Text('Logout'),
onTap: () => context.go('/'),
),
],
),
),
@ -140,40 +261,40 @@ class BaseScaffold extends StatelessWidget {
unselectedItemColor: Colors.grey,
showUnselectedLabels: true,
),
body: body,
body: widget.body,
);
}
//Map the current route to the selected index
// Map the current route to the selected index
int _getSelectedIndex(String route) {
switch (route) {
case '/':
case '/myhomepage':
return 0;
case '/uaenumbers':
case '/about':
return 1;
case '/competitiveness':
case '/settings':
return 2;
case '/countryprofile':
case '/profile':
return 3;
default:
return 0;
}
}
//Handle navigation when an item is tapped
// Handle navigation when an item is tapped
void _onItemTapped(BuildContext context, int index) {
switch (index) {
case 0:
context.go('/');
context.go('/myhomepage');
break;
case 1:
context.go('/uaenumbers');
context.go('/about');
break;
case 2:
context.go('/competitiveness');
context.go('/settings');
break;
case 3:
context.go('/countryprofile');
context.go('/profile');
break;
}
}

View File

@ -5,23 +5,23 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: "16e298750b6d0af7ce8a3ba7c18c69c3785d11b15ec83f6dcd0ad2a0009b3cab"
sha256: f256b0c0ba6c7577c15e2e4e114755640a875e885099367bf6e012b19314c834
url: "https://pub.dev"
source: hosted
version: "76.0.0"
version: "72.0.0"
_macros:
dependency: transitive
description: dart
source: sdk
version: "0.3.3"
version: "0.3.2"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: "1f14db053a8c23e260789e9b0980fa27f2680dd640932cae5e1137cce0e46e1e"
sha256: b652861553cd3990d8ed361f7979dc6d7053a9ac8843fa73820ab68ce5410139
url: "https://pub.dev"
source: hosted
version: "6.11.0"
version: "6.7.0"
analyzer_plugin:
dependency: transitive
description:
@ -186,10 +186,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.19.0"
version: "1.18.0"
convert:
dependency: transitive
description:
@ -266,10 +266,10 @@ packages:
dependency: transitive
description:
name: custom_lint_visitor
sha256: bfe9b7a09c4775a587b58d10ebb871d4fe618237639b1e84d5ec62d7dfef25f9
sha256: "8aeb3b6ae2bb765e7716b93d1d10e8356d04e0ff6d7592de6ee04e0dd7d6587d"
url: "https://pub.dev"
source: hosted
version: "1.0.0+6.11.0"
version: "1.0.0+6.7.0"
dart_style:
dependency: transitive
description:
@ -773,18 +773,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
url: "https://pub.dev"
source: hosted
version: "10.0.7"
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.dev"
source: hosted
version: "3.0.8"
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
@ -813,10 +813,10 @@ packages:
dependency: transitive
description:
name: macros
sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656"
sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536"
url: "https://pub.dev"
source: hosted
version: "0.1.3-main.0"
version: "0.1.2-main.4"
mailer:
dependency: "direct main"
description:
@ -1172,7 +1172,7 @@ packages:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
version: "0.0.99"
smart_api_client:
dependency: "direct main"
description:
@ -1216,10 +1216,10 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.11.1"
state_notifier:
dependency: transitive
description:
@ -1248,10 +1248,10 @@ packages:
dependency: transitive
description:
name: string_scanner
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.2.0"
syncfusion_flutter_charts:
dependency: "direct main"
description:
@ -1280,10 +1280,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
url: "https://pub.dev"
source: hosted
version: "0.7.3"
version: "0.7.2"
the_validator:
dependency: "direct main"
description:
@ -1408,10 +1408,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.3.0"
version: "14.2.5"
watcher:
dependency: transitive
description: