From 474606b488a7c53abca82ba03fe337d6966cbae4 Mon Sep 17 00:00:00 2001 From: VINISTAN Date: Wed, 27 Nov 2024 12:56:37 +0530 Subject: [PATCH] Manage User added --- assets/icons/drawer/manageuser.png | Bin 0 -> 364 bytes lib/config/my_router.dart | 14 +- .../icons/drawer_asset_icon_path.dart | 3 + lib/main.dart | 133 ++--- lib/presentation/components/my_drawer.dart | 8 +- .../drawer_routes/manage_user_router.dart | 486 ++++++++++++++++++ 6 files changed, 571 insertions(+), 73 deletions(-) create mode 100644 assets/icons/drawer/manageuser.png create mode 100644 lib/presentation/routes/drawer_routes/manage_user_router.dart diff --git a/assets/icons/drawer/manageuser.png b/assets/icons/drawer/manageuser.png new file mode 100644 index 0000000000000000000000000000000000000000..c87bdadf8cd4680323e1772e42a20a8641d2a864 GIT binary patch literal 364 zcmeAS@N?(olHy`uVBq!ia0vp^B0wy_!3HG7B;uuk6lZ})WHAE+w=f7ZGR&GI0Tg5` z4sv&5Sa(k5C6L3C?&#~tz_78O`%fY(P>#{l#WAFUaqZ-XyiEoIt@Drl-_>~6;ZB2~ z#6iIlrcxlhdBCF4iZL(2oI(9U`4Z_+0v@uUmR?m~j| zD^yhY@4iT{oHbSRsOssn+m9ZeHA68>^Of7O7YP{;`_jBVN>(mf>{np=`JvZ_%k|BD zlX$-Wc&xj9YRO?H+o@aq7{b|3-aCEFOoe*~7R$&q0PqrR5 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(), }, diff --git a/lib/infrastructure/services/img_asset_paths/icons/drawer_asset_icon_path.dart b/lib/infrastructure/services/img_asset_paths/icons/drawer_asset_icon_path.dart index 91a3172f..265d41f7 100644 --- a/lib/infrastructure/services/img_asset_paths/icons/drawer_asset_icon_path.dart +++ b/lib/infrastructure/services/img_asset_paths/icons/drawer_asset_icon_path.dart @@ -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'; } diff --git a/lib/main.dart b/lib/main.dart index df1ec5b7..4b000a4b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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; + } +} diff --git a/lib/presentation/components/my_drawer.dart b/lib/presentation/components/my_drawer.dart index 36bb04f5..d3ffe5e0 100644 --- a/lib/presentation/components/my_drawer.dart +++ b/lib/presentation/components/my_drawer.dart @@ -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, diff --git a/lib/presentation/routes/drawer_routes/manage_user_router.dart b/lib/presentation/routes/drawer_routes/manage_user_router.dart new file mode 100644 index 00000000..286f6d49 --- /dev/null +++ b/lib/presentation/routes/drawer_routes/manage_user_router.dart @@ -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 createState() => _ManageUserRouterState(); +// } +// +// class _ManageUserRouterState extends State { +// // Sample data for the table +// final List 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(Comparable 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 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( +// value: user.status, +// items: statusOptions.map((status) { +// return DropdownMenuItem( +// 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 createState() => _ManageUserRouterState(); +} + +class _ManageUserRouterState extends State { + // Sample data for the table + final List 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(Comparable 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 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 _showConfirmationDialog(User user, String newStatus) async { + double myheight = MediaQuery.of(context).size.height; + return showDialog( + 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: [ + // 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: [ + 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( + value: user.status, + items: statusOptions.map((status) { + return DropdownMenuItem( + 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', + }); +}