Profile UI & Product manual api integrate

This commit is contained in:
Vaibhav 2024-08-30 18:02:56 +05:30
parent 91912fcc95
commit b4bf13214a
8 changed files with 235 additions and 188 deletions

View File

@ -36,8 +36,6 @@ class ProductProvider extends ChangeNotifier {
} }
Future<void> getProducts() async { Future<void> getProducts() async {
// setLoading(true);
// try {
Response response = await _apiClient.get(ApiUrls.getProducts); Response response = await _apiClient.get(ApiUrls.getProducts);
debugPrint('Response: $response'); debugPrint('Response: $response');
setLoading(false); setLoading(false);
@ -49,10 +47,6 @@ class ProductProvider extends ChangeNotifier {
.toList(); .toList();
notifyListeners(); notifyListeners();
} }
// } catch (e) {
// setLoading(false);
// debugPrint("Error: $e");
// }
} }
Future<void> submitProducts( Future<void> submitProducts(

View File

@ -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<void> 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<void> 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()));
}
}
}

View File

@ -178,7 +178,7 @@ class _AddProductsScreenState extends State<AddProductsScreen> {
product.inventory != null)) { product.inventory != null)) {
value.submitProducts( value.submitProducts(
distributorType: widget.distributorType, distributorType: widget.distributorType,
pdRdId: widget.pdRdId, inventoryId: widget.inventoryId! pdRdId: widget.pdRdId, inventoryId: widget.inventoryId
); );
} else { } else {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(

View File

@ -63,22 +63,35 @@ class _UpdateInventoryTaskScreenState extends State<UpdateInventoryTaskScreen> {
Widget _buildTaskList() { Widget _buildTaskList() {
return Consumer<DailyTaskProvider>( return Consumer<DailyTaskProvider>(
builder: (context, value, child) => builder: (context, value, child) {
value.isLoading if (value.isLoading) {
? const Center(child: CircularProgressIndicator()) return 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();
} }
},
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<UpdateInventoryTaskScreen> {
], ],
), ),
trailing: const Icon(Icons.arrow_forward_ios, color: Colors.black87), trailing: const Icon(Icons.arrow_forward_ios, color: Colors.black87),
), ),
), ),
); );

View File

@ -204,7 +204,7 @@ class _DailyTasksScreenState extends State<DailyTasksScreen> {
builder: (context) => AddProductsScreen( builder: (context) => AddProductsScreen(
distributorType: tasksList.addedFor!, distributorType: tasksList.addedFor!,
tradeName: tasksList.tradeName?? '', tradeName: tasksList.tradeName?? '',
pdRdId: tasksList.sId!, inventoryId:tasksList.sId!))); pdRdId: tasksList.addedForId!, inventoryId:tasksList.sId)));
} else if (tasksList.task == 'Update Sales Data') { } else if (tasksList.task == 'Update Sales Data') {
Navigator.push( Navigator.push(
context, context,
@ -215,7 +215,7 @@ class _DailyTasksScreenState extends State<DailyTasksScreen> {
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => VisitDealersScreen( builder: (context) => VisitDealersScreen(
tradeName: tasksList.tradeName??'',id: tasksList.sId!, tradeName: tasksList.tradeName??'',
))); )));
} }
}, },

View File

@ -46,17 +46,6 @@ class RetailerDetailsScreenState extends State<RetailerDetailsScreen> {
Column( Column(
children: [ children: [
const SizedBox(height: 15), 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( CommonTextFormField(
title: 'Name', title: 'Name',
fillColor: Colors.white, fillColor: Colors.white,

View File

@ -41,7 +41,8 @@ class SelectTaskkycScreenState extends State<SelectTaskkycScreen> {
icon: Image.asset('assets/Back_attendance.png'), icon: Image.asset('assets/Back_attendance.png'),
padding: const EdgeInsets.only(right: 20), padding: const EdgeInsets.only(right: 20),
), ),
]), ],
),
drawer: const CommonDrawer(), drawer: const CommonDrawer(),
body: Consumer<SelectTaskProvider>( body: Consumer<SelectTaskProvider>(
builder: (context, value, child) => builder: (context, value, child) =>
@ -50,19 +51,31 @@ class SelectTaskkycScreenState extends State<SelectTaskkycScreen> {
: _buildTaskList(), : _buildTaskList(),
), ),
), ),
)); ),
);
} }
Widget _buildTaskList() { Widget _buildTaskList() {
return Consumer<SelectTaskProvider>(builder: (context, value, child) { return Consumer<SelectTaskProvider>(
builder: (context, value, child) {
if (value.tasksList.isEmpty) { if (value.tasksList.isEmpty) {
return const Center(child: Text('No tasks available')); return const Center(
child: Text(
'NO TASK',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
);
} }
return ListView.builder( return ListView.builder(
itemCount: value.tasksList.length, itemCount: value.tasksList.length,
itemBuilder: (context, index) => _buildTaskCard(value.tasksList[index]), itemBuilder: (context, index) => _buildTaskCard(value.tasksList[index]),
); );
}); },
);
} }
Widget _buildTaskCard(Tasks task) { Widget _buildTaskCard(Tasks task) {
@ -70,8 +83,9 @@ class SelectTaskkycScreenState extends State<SelectTaskkycScreen> {
onTap: () => Navigator.push( onTap: () => Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => builder: (context) => CollectKycScreen(id: task.taskId ?? ''),
CollectKycScreen(id: task.taskId ?? ''))), ),
),
child: Card( child: Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: Colors.white, color: Colors.white,
@ -90,10 +104,7 @@ class SelectTaskkycScreenState extends State<SelectTaskkycScreen> {
fontFamily: 'Anek', fontFamily: 'Anek',
), ),
), ),
trailing: trailing: const Icon(Icons.arrow_forward_ios, color: Colors.black87),
const Icon(Icons.arrow_forward_ios, color: Colors.black87),
), ),
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
@ -103,10 +114,9 @@ class SelectTaskkycScreenState extends State<SelectTaskkycScreen> {
Text('Note: ${task.note}'), Text('Note: ${task.note}'),
if (task.taskDueDate != null) if (task.taskDueDate != null)
Text( Text(
'Date: ${task.taskDueDate == null ? '' : DateFormat( 'Date: ${task.taskDueDate == null ? '' : DateFormat('dd/MM/yyyy').format(DateTime.parse(task.taskDueDate ?? ''))}',
'dd/MM/yyyy').format( ),
DateTime.parse(task.taskDueDate ?? ''))}'), Text('Priority: ${task.taskPriority}'),
Text('Priority: ${task.taskPriority}')
], ],
), ),
), ),

View File

@ -87,9 +87,7 @@ class VisitDealersScreenState extends State<VisitDealersScreen> {
elevation: 0, elevation: 0,
), ),
drawer: const CommonDrawer(), drawer: const CommonDrawer(),
body: Padding( body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@ -99,7 +97,7 @@ class VisitDealersScreenState extends State<VisitDealersScreen> {
Container( Container(
padding: padding:
const EdgeInsets.all(20.0).copyWith(top: 30, bottom: 30), const EdgeInsets.all(20.0).copyWith(top: 30, bottom: 30),
// margin: const EdgeInsets.symmetric(horizontal: 30.0), margin: const EdgeInsets.symmetric(horizontal: 16.0),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all(color: Colors.white), border: Border.all(color: Colors.white),
color: const Color(0xffB4D1E5).withOpacity(0.9), color: const Color(0xffB4D1E5).withOpacity(0.9),
@ -200,7 +198,6 @@ class VisitDealersScreenState extends State<VisitDealersScreen> {
), ),
), ),
), ),
),
); );
} }
} }