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 {
// 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<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)) {
value.submitProducts(
distributorType: widget.distributorType,
pdRdId: widget.pdRdId, inventoryId: widget.inventoryId!
pdRdId: widget.pdRdId, inventoryId: widget.inventoryId
);
} else {
ScaffoldMessenger.of(context).showSnackBar(

View File

@ -63,22 +63,35 @@ class _UpdateInventoryTaskScreenState extends State<UpdateInventoryTaskScreen> {
Widget _buildTaskList() {
return Consumer<DailyTaskProvider>(
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<UpdateInventoryTaskScreen> {
],
),
trailing: const Icon(Icons.arrow_forward_ios, color: Colors.black87),
),
),
);

View File

@ -203,8 +203,8 @@ class _DailyTasksScreenState extends State<DailyTasksScreen> {
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<DailyTasksScreen> {
context,
MaterialPageRoute(
builder: (context) => VisitDealersScreen(
tradeName: tasksList.tradeName??'',id: tasksList.sId!,
tradeName: tasksList.tradeName??'',
)));
}
},

View File

@ -46,17 +46,6 @@ class RetailerDetailsScreenState extends State<RetailerDetailsScreen> {
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,

View File

@ -27,51 +27,65 @@ class SelectTaskkycScreenState extends State<SelectTaskkycScreen> {
@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<SelectTaskProvider>(
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<SelectTaskProvider>(
builder: (context, value, child) =>
value.isLoading
? const Center(child: CircularProgressIndicator())
: _buildTaskList(),
),
),
),
);
}
Widget _buildTaskList() {
return Consumer<SelectTaskProvider>(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<SelectTaskProvider>(
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<SelectTaskkycScreen> {
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<SelectTaskkycScreen> {
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}'),
],
),
),

View File

@ -87,116 +87,113 @@ class VisitDealersScreenState extends State<VisitDealersScreen> {
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: <Widget>[
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: <Widget>[
CommonTextFormField(
body: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
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: <Widget>[
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<String>(
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<String>(
decoration: const InputDecoration(
labelText: 'Purpose of visit',
fillColor: Colors.white,
filled: true,
),
value: selectedPurpose,
items: purposeOptions.map((String value) {
return DropdownMenuItem<String>(
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<String>(
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<VisitPdRdProvider>(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<VisitPdRdProvider>(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 ?? '');
},
),
),
],
),
),
],
),
],
),
),
],
),
),
),