Manage User added

This commit is contained in:
VINISTAN 2024-11-27 12:56:37 +05:30
parent 1025ef60a1
commit 474606b488
6 changed files with 571 additions and 73 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

View File

@ -34,6 +34,7 @@ import 'package:uae_stat/presentation/routes/bottom_bar_routes/tab_routes/uae_nu
import 'package:uae_stat/presentation/routes/bottom_bar_routes/tab_routes/uae_numbers_routes/sub_routes/social/_labor_force_body.dart';
import 'package:uae_stat/presentation/routes/bottom_bar_routes/tab_routes/uae_numbers_routes/sub_routes/social/_population_body.dart';
import 'package:uae_stat/presentation/routes/drawer_routes/feedback_route.dart';
import 'package:uae_stat/presentation/routes/drawer_routes/manage_user_router.dart';
import 'package:uae_stat/presentation/routes/drawer_routes/my_favorites_route.dart';
import 'package:uae_stat/presentation/routes/drawer_routes/privacy_policy_route.dart';
import 'package:uae_stat/presentation/routes/drawer_routes/profile/reset_pw_route.dart';
@ -65,12 +66,12 @@ class _MyRouter {
}
Iterable<GoRoute> get authRoutes => [
GoRoute(
path: 'Profile',
redirect: (context, state) =>
isLoggedIn ? null : '${context.language.name}/profile',
builder: (context, state) => const ProfileRoute(),
),
GoRoute(
path: 'Profile',
redirect: (context, state) =>
isLoggedIn ? null : '${context.language.name}/profile',
builder: (context, state) => const ProfileRoute(),
),
GoRoute(
path: 'login',
redirect: (context, state) =>
@ -198,6 +199,7 @@ class _MyRouter {
//DrawerItems.feedback => const FeedbackRoute(),
DrawerItems.feedback => FeedbackForm(),
DrawerItems.privacyPolicy => const PrivacyPolicyRoute(),
DrawerItems.manageuser => ManageUserRouter()
// DrawerItems.userGuide => const NotificationsRoute(),
// DrawerItems.notifications => const UserGuideRoute(),
},

View File

@ -1,3 +1,5 @@
import 'package:flutter/material.dart';
abstract class DrawerAssetIconPath {
static const _basePath = 'assets/icons/drawer';
static const bell = '$_basePath/bell.png';
@ -5,4 +7,5 @@ abstract class DrawerAssetIconPath {
static const favorites = '$_basePath/bookmarks.png';
static const message = '$_basePath/message.png';
static const scroll = '$_basePath/scroll.png';
static const manageuser = '$_basePath/manageuser.png';
}

View File

@ -22,75 +22,76 @@ void main() async {
);
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: RegisterScreen(),
//home: ProfileScreen(),
debugShowCheckedModeBanner: false,
);
}
}
// class MainApp extends ConsumerWidget {
// class MainApp extends StatelessWidget {
// const MainApp({super.key});
//
// @override
// Widget build(
// BuildContext context,
// WidgetRef ref,
// ) {
// const loading = Material(
// child: Center(
// child: CircularProgressIndicator(),
// ),
// Widget build(BuildContext context) {
// return MaterialApp(
//
// home: RegisterScreen(),
// //home: ProfileScreen(),
// debugShowCheckedModeBanner: false,
// );
// // waits to load preferences (language)
// // from local storage
// final languageFinalizedWidget = ref
// .watch(
// routerProvider,
// )
// .when(
// loading: () => loading,
// error: Error.throwWithStackTrace,
// data: (data) {
// final materialApp = MaterialApp.router(
// debugShowCheckedModeBanner: false,
// routerConfig: data,
// supportedLocales: LanguageLocale.values.map(
// (e) => e.toLocale(),
// ),
// localizationsDelegates: GlobalMaterialLocalizations.delegates,
// theme: ThemeData.from(
// colorScheme: ColorScheme.fromSeed(
// seedColor: MyTheme.topicColor(
// IndicatorTopic.economy,
// ),
// ),
// textTheme: OldTheme.textTheme,
// ),
// );
// return ColoredBox(
// color: Colors.white,
// child: materialApp,
// );
// },
// );
// // waits to load auth from local storage
// final authFinalizedWidget = ref
// .watch(
// authUseCaseProvider,
// )
// .when(
// loading: () => loading,
// error: Error.throwWithStackTrace,
// data: (data) => languageFinalizedWidget,
// );
// return authFinalizedWidget;
// }
// }
class MainApp extends ConsumerWidget {
const MainApp({super.key});
@override
Widget build(
BuildContext context,
WidgetRef ref,
) {
const loading = Material(
child: Center(
child: CircularProgressIndicator(),
),
);
// waits to load preferences (language)
// from local storage
final languageFinalizedWidget = ref
.watch(
routerProvider,
)
.when(
loading: () => loading,
error: Error.throwWithStackTrace,
data: (data) {
final materialApp = MaterialApp.router(
debugShowCheckedModeBanner: false,
routerConfig: data,
supportedLocales: LanguageLocale.values.map(
(e) => e.toLocale(),
),
localizationsDelegates: GlobalMaterialLocalizations.delegates,
theme: ThemeData.from(
colorScheme: ColorScheme.fromSeed(
seedColor: MyTheme.topicColor(
IndicatorTopic.economy,
),
),
textTheme: OldTheme.textTheme,
),
);
return ColoredBox(
color: Colors.white,
child: materialApp,
);
},
);
// waits to load auth from local storage
final authFinalizedWidget = ref
.watch(
authUseCaseProvider,
)
.when(
loading: () => loading,
error: Error.throwWithStackTrace,
data: (data) => languageFinalizedWidget,
);
return authFinalizedWidget;
}
}

View File

@ -237,6 +237,12 @@ enum DrawerItems {
titleAR: 'المفضلات',
imgPath: DrawerAssetIconPath.favorites,
),
manageuser(
routePath: 'manageuser',
titleEN: 'Manage User',
titleAR: 'شاركنا رأيك',
imgPath: DrawerAssetIconPath.manageuser,
),
feedback(
routePath: 'feedback',
titleEN: 'Feedback',
@ -250,7 +256,7 @@ enum DrawerItems {
imgPath: DrawerAssetIconPath.scroll,
);
const DrawerItems({
const DrawerItems({
required this.routePath,
required this.titleEN,
required this.titleAR,

View File

@ -0,0 +1,486 @@
// import 'package:flutter/material.dart';
// import 'package:uae_stat/presentation/components/my_bottom_nav_bar.dart';
// import 'package:uae_stat/presentation/components/my_drawer.dart';
//
//
// class ManageUserRouter extends StatefulWidget {
// @override
// State<ManageUserRouter> createState() => _ManageUserRouterState();
// }
//
// class _ManageUserRouterState extends State<ManageUserRouter> {
// // Sample data for the table
// final List<User> userData = List.generate(
// 5,
// (index) => User(
// userName: 'Conan Keller ${index + 1}',
// emailId: 'ConanKeller${index + 1}@gmail.com',
// registrationDate: '18/07/2024',
// status: 'Pending',
// ),
// );
//
// // Sorting state
// int _sortColumnIndex = 0;
// bool _isAscending = true;
//
// // Method to sort the data based on a column
// void _sort<T>(Comparable<T> Function(User user) getField, int columnIndex, bool ascending) {
// setState(() {
// _sortColumnIndex = columnIndex;
// _isAscending = ascending;
// userData.sort((a, b) {
// final aValue = getField(a);
// final bValue = getField(b);
// return ascending ? Comparable.compare(aValue, bValue) : Comparable.compare(bValue, aValue);
// });
// });
// }
//
// // Define dropdown items
// final List<String> statusOptions = ['Approved', 'Denied', 'Pending'];
//
// // Method to get status color
// Color getStatusColor(String status) {
// switch (status) {
// case 'Approved':
// return Colors.green;
// case 'Denied':
// return Colors.red;
// case 'Pending':
// return Colors.blue;
// default:
// return Colors.black;
// }
// }
//
//
//
// @override
// Widget build(BuildContext context) {
// double myheight = MediaQuery.of(context).size.height;
// return Scaffold(
// drawer: MyDrawer(),
// appBar: AppBar(
// title: const Text('Manage User',style: TextStyle(fontWeight: FontWeight.bold),),
// ),
// body: SingleChildScrollView(
// child: Padding(
// padding: const EdgeInsets.only(left: 10.0,right: 10.0,top: 3.0),
// child: Column(
// children: [
// TextField(
// decoration: InputDecoration(
// prefixIcon: const Icon(Icons.search),
// hintText: 'Search',
// border: OutlineInputBorder(
// borderRadius: BorderRadius.all(Radius.circular(20)),
// ),
// ),
// ),
// SizedBox(height: myheight/40,),
// SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child:
// DataTable(
// sortColumnIndex: _sortColumnIndex,
// sortAscending: _isAscending,
// columns: [
// DataColumn(
// label: const Text('User Name'),
// //label: Row(children: [Text('Name'),Icon(Icons.arrow_upward),Icon(Icons.arrow_downward)],),
// onSort: (columnIndex, ascending) => _sort((user) => user.userName, columnIndex, ascending),
// numeric: false
// ),
// DataColumn(
// label: const Text('Email ID'),
// onSort: (columnIndex, ascending) => _sort((user) => user.emailId, columnIndex, ascending),
// numeric: false
// ),
// DataColumn(
// label: const Text('Registration Date'),
// onSort: (columnIndex, ascending) => _sort((user) => user.registrationDate, columnIndex, ascending),
// numeric: false
// ),
// DataColumn(
// label: const Text('Status'),
// onSort: (columnIndex, ascending) => _sort((user) => user.status, columnIndex, ascending),
// numeric: false
// ),
// ],
// rows: userData.map((user) {
// return DataRow(
// cells: [
// DataCell(Text(user.userName)),
// DataCell(Text(user.emailId)),
// DataCell(Text(user.registrationDate)),
// DataCell(
// DropdownButton<String>(
// value: user.status,
// items: statusOptions.map((status) {
// return DropdownMenuItem<String>(
// value: status,
// child: Text(
// status,
// style: TextStyle(color: getStatusColor(status)),
// ),
// );
// }).toList(),
// onChanged: (String? newStatus) {
// if (newStatus != null) {
// setState(() {
// user.status = newStatus;
// });
// }
// },
// ),
// ),
// ],
// );
// }).toList(),
// ),
// ),
// ],
// ),
// ),
// ),
// );
// }
// }
//
//
//
//
// // User data model
// class User {
// final String userName;
// final String emailId;
// final String registrationDate;
// String status;
//
// User({
// required this.userName,
// required this.emailId,
// required this.registrationDate,
// this.status = 'Pending',
// });
// }
//
//
//
import 'package:flutter/material.dart';
import 'package:uae_stat/presentation/components/my_bottom_nav_bar.dart';
import 'package:uae_stat/presentation/components/my_drawer.dart';
class ManageUserRouter extends StatefulWidget {
@override
State<ManageUserRouter> createState() => _ManageUserRouterState();
}
class _ManageUserRouterState extends State<ManageUserRouter> {
// Sample data for the table
final List<User> userData = List.generate(
5,
(index) => User(
userName: 'Conan Keller ${index + 1}',
emailId: 'ConanKeller${index + 1}@gmail.com',
registrationDate: '18/07/2024',
status: 'Pending',
),
);
// Sorting state
int _sortColumnIndex = 0;
bool _isAscending = true;
// Method to sort the data based on a column
void _sort<T>(Comparable<T> Function(User user) getField, int columnIndex,
bool ascending) {
setState(() {
_sortColumnIndex = columnIndex;
_isAscending = ascending;
userData.sort((a, b) {
final aValue = getField(a);
final bValue = getField(b);
return ascending
? Comparable.compare(aValue, bValue)
: Comparable.compare(bValue, aValue);
});
});
}
// Define dropdown items
final List<String> statusOptions = ['Approved', 'Denied', 'Pending'];
// Method to get status color
Color getStatusColor(String status) {
switch (status) {
case 'Approved':
return Colors.green;
case 'Denied':
return Colors.red;
case 'Pending':
return Colors.blue;
default:
return Colors.black;
}
}
//Method to show a confirmation dialog when status is changed
Future<void> _showConfirmationDialog(User user, String newStatus) async {
double myheight = MediaQuery.of(context).size.height;
return showDialog<void>(
context: context,
barrierDismissible: false, // User must tap button to dismiss dialog
builder: (BuildContext context) {
return
// AlertDialog(
// shape:
// RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
// content: Padding(
// padding: const EdgeInsets.all(8.0),
// child: Text(
// 'Are you sure you want to change \n the status to $newStatus?',
// style: TextStyle(fontSize: 15),
// ),
// ),
// actions: <Widget>[
// Center(
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
// children: [
// TextButton(
// onPressed: () {
// Navigator.of(context)
// .pop(); // Close dialog without changing status
// },
// style: TextButton.styleFrom(
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(
// 10.0), // Adjust the radius as needed
// ),
// side: BorderSide(
// color: Colors.blue, // Set the outline color
// width: 2.0, // Set the border width
// ),
// ),
// child: Text('No'),
// ),
// TextButton(
// onPressed: () {
// setState(() {
// user.status = newStatus; // Change status
// });
// Navigator.of(context).pop();
// },
// style: TextButton.styleFrom(
// backgroundColor: Colors.blue, // Set background color
// foregroundColor: Colors.white,
// shape: RoundedRectangleBorder(
// borderRadius:
// BorderRadius.circular(10.0), // Set text color
// )),
// child: Text(
// 'Yes',
// style: TextStyle(color: Colors.white),
// ),
// ),
// ],
// ))
// ],
// );
AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0), // Rounded corners
),
contentPadding: EdgeInsets.zero, // Ensure no padding issues with close icon
content: Stack(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(height: myheight/30,),
Text(
'Are you sure you want to change \n the status to $newStatus?',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center,
),
],
),
),
Positioned(
right: 0,
top: 0,
child: IconButton(
icon: Icon(Icons.close),
onPressed: () {
Navigator.of(context).pop(); // Close the dialog
},
),
),
],
),
actions: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
TextButton(
onPressed: () {
Navigator.of(context)
.pop(); // Close dialog without changing status
},
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
10.0), // Adjust the radius as needed
),
side: BorderSide(
color: Colors.blue, // Set the outline color
width: 2.0, // Set the border width
),
),
child: Text('No'),
),
TextButton(
onPressed: () {
setState(() {
user.status = newStatus; // Change status
});
Navigator.of(context).pop();
},
style: TextButton.styleFrom(
backgroundColor: Colors.blue, // Set background color
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(10.0), // Set text color
)),
child: Text(
'Yes',
style: TextStyle(color: Colors.white),
),
),
],
)
],
);
},
);
}
@override
Widget build(BuildContext context) {
double myheight = MediaQuery.of(context).size.height;
return Scaffold(
drawer: MyDrawer(),
appBar: AppBar(
title: const Text('Manage User',
style: TextStyle(fontWeight: FontWeight.bold)),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.only(left: 10.0, right: 10.0, top: 3.0),
child: Column(
children: [
TextField(
decoration: InputDecoration(
prefixIcon: const Icon(Icons.search),
hintText: 'Search',
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
),
),
),
SizedBox(height: myheight / 40),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
sortColumnIndex: _sortColumnIndex,
sortAscending: _isAscending,
columns: [
DataColumn(
label: const Text('User Name'),
onSort: (columnIndex, ascending) => _sort(
(user) => user.userName, columnIndex, ascending),
numeric: false,
),
DataColumn(
label: const Text('Email ID'),
onSort: (columnIndex, ascending) =>
_sort((user) => user.emailId, columnIndex, ascending),
numeric: false,
),
DataColumn(
label: const Text('Registration Date'),
onSort: (columnIndex, ascending) => _sort(
(user) => user.registrationDate,
columnIndex,
ascending),
numeric: false,
),
DataColumn(
label: const Text('Status'),
onSort: (columnIndex, ascending) =>
_sort((user) => user.status, columnIndex, ascending),
numeric: false,
),
],
rows: userData.map((user) {
return DataRow(
cells: [
DataCell(Text(user.userName)),
DataCell(Text(user.emailId)),
DataCell(Text(user.registrationDate)),
DataCell(
DropdownButton<String>(
value: user.status,
items: statusOptions.map((status) {
return DropdownMenuItem<String>(
value: status,
child: Text(
status,
style:
TextStyle(color: getStatusColor(status)),
),
);
}).toList(),
onChanged: (String? newStatus) {
if (newStatus != null) {
_showConfirmationDialog(user,
newStatus); // Show dialog for confirmation
}
},
),
),
],
);
}).toList(),
),
),
],
),
),
),
);
}
}
// User data model
class User {
final String userName;
final String emailId;
final String registrationDate;
String status;
User({
required this.userName,
required this.emailId,
required this.registrationDate,
this.status = 'Pending',
});
}