diff --git a/lib/provider/products_provider.dart b/lib/provider/products_provider.dart index 12c1196..44f10fa 100644 --- a/lib/provider/products_provider.dart +++ b/lib/provider/products_provider.dart @@ -36,8 +36,6 @@ class ProductProvider extends ChangeNotifier { } Future getProducts() async { - // setLoading(true); - // try { Response response = await _apiClient.get(ApiUrls.getProducts); debugPrint('Response: $response'); setLoading(false); @@ -49,10 +47,6 @@ class ProductProvider extends ChangeNotifier { .toList(); notifyListeners(); } - // } catch (e) { - // setLoading(false); - // debugPrint("Error: $e"); - // } } Future submitProducts( diff --git a/lib/provider/userprofile_provider.dart b/lib/provider/userprofile_provider.dart new file mode 100644 index 0000000..949291b --- /dev/null +++ b/lib/provider/userprofile_provider.dart @@ -0,0 +1,45 @@ +import 'package:cheminova/models/profile_response.dart'; +import 'package:cheminova/services/api_client.dart'; +import 'package:cheminova/services/api_urls.dart'; +import 'package:cheminova/services/secure__storage_service.dart'; +import 'package:dio/dio.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import '../screens/login_screen.dart'; + +class UserprofileProvider extends ChangeNotifier { + final _apiClient = ApiClient(); + ProfileResponse? profileResponse; + bool _isLoading = false; + + bool get isLoading => _isLoading; + + void setLoading(bool loading) { + _isLoading = loading; + notifyListeners(); + } + + Future getProfile() async { + setLoading(true); + try { + Response response = await _apiClient.get(ApiUrls.profileUrl); + setLoading(false); + if (response.statusCode == 200) { + profileResponse = ProfileResponse.fromJson(response.data); + } else {} + } catch (e) { + setLoading(false); + } + } + + Future logOut(BuildContext context) async { + Response response = await _apiClient.get(ApiUrls.logOutUrl); + if (response.statusCode == 200) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(response.data['message'].toString()))); + SecureStorageService().clear(); + Navigator.pushReplacement( + context, MaterialPageRoute(builder: (context) => const LoginPage())); + } + } +} diff --git a/lib/screens/Add_products_screen.dart b/lib/screens/Add_products_screen.dart index a42c3e2..c89bccd 100644 --- a/lib/screens/Add_products_screen.dart +++ b/lib/screens/Add_products_screen.dart @@ -178,7 +178,7 @@ class _AddProductsScreenState extends State { product.inventory != null)) { value.submitProducts( distributorType: widget.distributorType, - pdRdId: widget.pdRdId, inventoryId: widget.inventoryId! + pdRdId: widget.pdRdId, inventoryId: widget.inventoryId ); } else { ScaffoldMessenger.of(context).showSnackBar( diff --git a/lib/screens/Update_inventorytask_screen.dart b/lib/screens/Update_inventorytask_screen.dart index 374df77..f611507 100644 --- a/lib/screens/Update_inventorytask_screen.dart +++ b/lib/screens/Update_inventorytask_screen.dart @@ -63,22 +63,35 @@ class _UpdateInventoryTaskScreenState extends State { Widget _buildTaskList() { return Consumer( - builder: (context, value, child) => - value.isLoading - ? const Center(child: CircularProgressIndicator()) - : ListView.separated( - padding: const EdgeInsets.all(16), - itemCount: value.newTasksList.length, - separatorBuilder: (context, index) => const SizedBox(height: 8), - itemBuilder: (context, index) { - final task = value.newTasksList[index]; - if (task.task?.toLowerCase() == 'update inventory data') { - return _buildTaskCard(task); - } else { - return const SizedBox.shrink(); - } - }, - ), + builder: (context, value, child) { + if (value.isLoading) { + return const Center(child: CircularProgressIndicator()); + } + + final inventoryTasks = value.newTasksList + .where((task) => task.task?.toLowerCase() == 'update inventory data') + .toList(); + + if (inventoryTasks.isEmpty) { + return const Center( + child: Text( + 'NO TASK', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + color: Colors.black87, + ), + ), + ); + } + + return ListView.separated( + padding: const EdgeInsets.all(16), + itemCount: inventoryTasks.length, + separatorBuilder: (context, index) => const SizedBox(height: 8), + itemBuilder: (context, index) => _buildTaskCard(inventoryTasks[index]), + ); + }, ); } @@ -119,7 +132,6 @@ class _UpdateInventoryTaskScreenState extends State { ], ), trailing: const Icon(Icons.arrow_forward_ios, color: Colors.black87), - ), ), ); diff --git a/lib/screens/daily_tasks_screen.dart b/lib/screens/daily_tasks_screen.dart index a28aed2..fe71576 100644 --- a/lib/screens/daily_tasks_screen.dart +++ b/lib/screens/daily_tasks_screen.dart @@ -203,8 +203,8 @@ class _DailyTasksScreenState extends State { MaterialPageRoute( builder: (context) => AddProductsScreen( distributorType: tasksList.addedFor!, - tradeName: tasksList.tradeName ?? '', - pdRdId: tasksList.sId!, inventoryId:tasksList.sId!))); + tradeName: tasksList.tradeName?? '', + pdRdId: tasksList.addedForId!, inventoryId:tasksList.sId))); } else if (tasksList.task == 'Update Sales Data') { Navigator.push( context, @@ -215,7 +215,7 @@ class _DailyTasksScreenState extends State { context, MaterialPageRoute( builder: (context) => VisitDealersScreen( - tradeName: tasksList.tradeName??'',id: tasksList.sId!, + tradeName: tasksList.tradeName??'', ))); } }, diff --git a/lib/screens/retailer_details_screen.dart b/lib/screens/retailer_details_screen.dart index 02c743e..7de7e01 100644 --- a/lib/screens/retailer_details_screen.dart +++ b/lib/screens/retailer_details_screen.dart @@ -46,17 +46,6 @@ class RetailerDetailsScreenState extends State { Column( children: [ const SizedBox(height: 15), - CommonTextFormField( - title: 'Trade Name', - fillColor: Colors.white, - validator: (String? value) { - if (value!.isEmpty) { - return 'Trade Name cannot be empty'; - } - return null; - }, - controller: value.tradeNameController), - const SizedBox(height: 15), CommonTextFormField( title: 'Name', fillColor: Colors.white, diff --git a/lib/screens/select_taskkyc_screen.dart b/lib/screens/select_taskkyc_screen.dart index 01793bd..31f7af6 100644 --- a/lib/screens/select_taskkyc_screen.dart +++ b/lib/screens/select_taskkyc_screen.dart @@ -27,51 +27,65 @@ class SelectTaskkycScreenState extends State { @override Widget build(BuildContext context) { return ChangeNotifierProvider( - create: (context) => _selectTaskProvider, - child: CommonBackground( - child: Scaffold( + create: (context) => _selectTaskProvider, + child: CommonBackground( + child: Scaffold( + backgroundColor: Colors.transparent, + appBar: CommonAppBar( + title: const Text('Select Task'), backgroundColor: Colors.transparent, - appBar: CommonAppBar( - title: const Text('Select Task'), - backgroundColor: Colors.transparent, - elevation: 0, - actions: [ - IconButton( - onPressed: () => Navigator.pop(context), - icon: Image.asset('assets/Back_attendance.png'), - padding: const EdgeInsets.only(right: 20), - ), - ]), - drawer: const CommonDrawer(), - body: Consumer( - builder: (context, value, child) => - value.isLoading - ? const Center(child: CircularProgressIndicator()) - : _buildTaskList(), - ), + elevation: 0, + actions: [ + IconButton( + onPressed: () => Navigator.pop(context), + icon: Image.asset('assets/Back_attendance.png'), + padding: const EdgeInsets.only(right: 20), + ), + ], ), - )); + drawer: const CommonDrawer(), + body: Consumer( + builder: (context, value, child) => + value.isLoading + ? const Center(child: CircularProgressIndicator()) + : _buildTaskList(), + ), + ), + ), + ); } Widget _buildTaskList() { - return Consumer(builder: (context, value, child) { - if (value.tasksList.isEmpty) { - return const Center(child: Text('No tasks available')); - } - return ListView.builder( - itemCount: value.tasksList.length, - itemBuilder: (context, index) => _buildTaskCard(value.tasksList[index]), - ); - }); + return Consumer( + builder: (context, value, child) { + if (value.tasksList.isEmpty) { + return const Center( + child: Text( + 'NO TASK', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + color: Colors.black87, + ), + ), + ); + } + return ListView.builder( + itemCount: value.tasksList.length, + itemBuilder: (context, index) => _buildTaskCard(value.tasksList[index]), + ); + }, + ); } Widget _buildTaskCard(Tasks task) { return InkWell( - onTap: () => Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - CollectKycScreen(id: task.taskId ?? ''))), + onTap: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => CollectKycScreen(id: task.taskId ?? ''), + ), + ), child: Card( margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), color: Colors.white, @@ -90,10 +104,7 @@ class SelectTaskkycScreenState extends State { fontFamily: 'Anek', ), ), - trailing: - const Icon(Icons.arrow_forward_ios, color: Colors.black87), - - + trailing: const Icon(Icons.arrow_forward_ios, color: Colors.black87), ), Padding( padding: const EdgeInsets.all(8.0), @@ -103,10 +114,9 @@ class SelectTaskkycScreenState extends State { Text('Note: ${task.note}'), if (task.taskDueDate != null) Text( - 'Date: ${task.taskDueDate == null ? '' : DateFormat( - 'dd/MM/yyyy').format( - DateTime.parse(task.taskDueDate ?? ''))}'), - Text('Priority: ${task.taskPriority}') + 'Date: ${task.taskDueDate == null ? '' : DateFormat('dd/MM/yyyy').format(DateTime.parse(task.taskDueDate ?? ''))}', + ), + Text('Priority: ${task.taskPriority}'), ], ), ), @@ -136,4 +146,4 @@ class KycTaskItem extends TaskItem { required this.date, required this.priority, }) : super(title: title, screen: screen); -} +} \ No newline at end of file diff --git a/lib/screens/visit_rd_pd_screen.dart b/lib/screens/visit_rd_pd_screen.dart index cb97472..b3d0c35 100644 --- a/lib/screens/visit_rd_pd_screen.dart +++ b/lib/screens/visit_rd_pd_screen.dart @@ -87,116 +87,113 @@ class VisitDealersScreenState extends State { elevation: 0, ), drawer: const CommonDrawer(), - body: Padding( - padding: const EdgeInsets.all(16.0), - child: SingleChildScrollView( - physics: const BouncingScrollPhysics(), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const SizedBox(height: 16), - Container( - padding: - const EdgeInsets.all(20.0).copyWith(top: 30, bottom: 30), - // margin: const EdgeInsets.symmetric(horizontal: 30.0), - decoration: BoxDecoration( - border: Border.all(color: Colors.white), - color: const Color(0xffB4D1E5).withOpacity(0.9), - borderRadius: BorderRadius.circular(26.0)), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - CommonTextFormField( + body: SingleChildScrollView( + physics: const BouncingScrollPhysics(), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox(height: 16), + Container( + padding: + const EdgeInsets.all(20.0).copyWith(top: 30, bottom: 30), + margin: const EdgeInsets.symmetric(horizontal: 16.0), + decoration: BoxDecoration( + border: Border.all(color: Colors.white), + color: const Color(0xffB4D1E5).withOpacity(0.9), + borderRadius: BorderRadius.circular(26.0)), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + CommonTextFormField( + readOnly: true, + title: 'Select Retailer', + fillColor: Colors.white, + controller: retailerController), + const SizedBox(height: 15), + CommonTextFormField( + title: 'Visit date', readOnly: true, - title: 'Select Retailer', - fillColor: Colors.white, - controller: retailerController), - const SizedBox(height: 15), - CommonTextFormField( - title: 'Visit date', - readOnly: true, - fillColor: Colors.white, - controller: dateController), - const SizedBox(height: 15), - CommonTextFormField( - title: 'Time', - readOnly: true, - fillColor: Colors.white, - controller: timeController), - const SizedBox(height: 15), - DropdownButtonFormField( - decoration: const InputDecoration( - labelText: 'Purpose of visit', - fillColor: Colors.white, - filled: true, + fillColor: Colors.white, + controller: dateController), + const SizedBox(height: 15), + CommonTextFormField( + title: 'Time', + readOnly: true, + fillColor: Colors.white, + controller: timeController), + const SizedBox(height: 15), + DropdownButtonFormField( + decoration: const InputDecoration( + labelText: 'Purpose of visit', + fillColor: Colors.white, + filled: true, + ), + value: selectedPurpose, + items: purposeOptions.map((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }).toList(), + onChanged: (String? newValue) { + setState(() { + selectedPurpose = newValue!; + }); + }, + ), + const SizedBox(height: 15), + CommonTextFormField( + title: 'Meeting Summary:', + fillColor: Colors.white, + maxLines: 4, + controller: meetingSummaryController), + const SizedBox(height: 15), + CommonTextFormField( + title: 'Follow-up Actions:', + fillColor: Colors.white, + maxLines: 4, + controller: followUpActionsController), + const SizedBox(height: 15), + CommonTextFormField( + title: 'Next visit date:', + readOnly: true, + fillColor: Colors.white, + controller: nextVisitDateController), + const SizedBox(height: 15), + Row( + children: [ + Expanded( + child: CommonTextFormField( + title: 'Attach Documents/Photos', + fillColor: Colors.white, + controller: notesController), ), - value: selectedPurpose, - items: purposeOptions.map((String value) { - return DropdownMenuItem( - value: value, - child: Text(value), - ); - }).toList(), - onChanged: (String? newValue) { - setState(() { - selectedPurpose = newValue!; - }); - }, - ), - const SizedBox(height: 15), - CommonTextFormField( - title: 'Meeting Summary:', - fillColor: Colors.white, - maxLines: 4, - controller: meetingSummaryController), - const SizedBox(height: 15), - CommonTextFormField( - title: 'Follow-up Actions:', - fillColor: Colors.white, - maxLines: 4, - controller: followUpActionsController), - const SizedBox(height: 15), - CommonTextFormField( - title: 'Next visit date:', - readOnly: true, - fillColor: Colors.white, - controller: nextVisitDateController), - const SizedBox(height: 15), - Row( - children: [ - Expanded( - child: CommonTextFormField( - title: 'Attach Documents/Photos', - fillColor: Colors.white, - controller: notesController), - ), - IconButton( - icon: const Icon(Icons.camera_alt), - onPressed: _pickImage, - ), - ], - ), - const SizedBox(height: 15), - Consumer(builder: (context, value, child) => Align( - alignment: Alignment.center, - child: CommonElevatedButton( - borderRadius: 30, - width: double.infinity, - height: kToolbarHeight - 10, - text: 'SUBMIT', - backgroundColor: const Color(0xff004791), - onPressed: () { - value.submitVisitPdRd(widget.id ?? ''); - }, - ), + IconButton( + icon: const Icon(Icons.camera_alt), + onPressed: _pickImage, + ), + ], + ), + const SizedBox(height: 15), + Consumer(builder: (context, value, child) => Align( + alignment: Alignment.center, + child: CommonElevatedButton( + borderRadius: 30, + width: double.infinity, + height: kToolbarHeight - 10, + text: 'SUBMIT', + backgroundColor: const Color(0xff004791), + onPressed: () { + value.submitVisitPdRd(widget.id ?? ''); + }, ), ), - ], - ), + ), + ], ), - ], - ), + ), + ], ), ), ),