Date Filter in Dashboard - Partner
This commit is contained in:
parent
6c92692fa9
commit
0eea319f49
File diff suppressed because one or more lines are too long
@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
import 'package:nhance_partner/data/services/auth_service.dart';
|
import 'package:nhance_partner/data/services/auth_service.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
@ -783,14 +784,33 @@ class ApiService {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>> findPartnerDashboardData(id, broker) async {
|
Future<Map<String, dynamic>> findPartnerDashboardData(id, fromDate,toDate) async {
|
||||||
// print(_token);
|
// print(_token);
|
||||||
if (_token == null) {
|
if (_token == null) {
|
||||||
await _initializeToken();
|
await _initializeToken();
|
||||||
}
|
}
|
||||||
final url = Uri.parse(
|
|
||||||
'${Env.apiUrl}dashboard/partnerDashboard?manager_id=$id',
|
late Uri url;
|
||||||
);
|
|
||||||
|
/// ✅ CASE 1: fromDate OR toDate is null → normal API
|
||||||
|
if (fromDate == null || toDate == null) {
|
||||||
|
url = Uri.parse(
|
||||||
|
'${Env.apiUrl}dashboard/partnerDashboard?manager_id=$id',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/// ✅ CASE 2: both dates present → filtered API
|
||||||
|
else {
|
||||||
|
final from = DateFormat('dd-MM-yyyy').format(fromDate);
|
||||||
|
final to = DateFormat('dd-MM-yyyy').format(toDate);
|
||||||
|
|
||||||
|
url = Uri.parse(
|
||||||
|
'${Env.apiUrl}dashboard/partnerDashboard'
|
||||||
|
'?manager_id=$id'
|
||||||
|
'&from_date=$from'
|
||||||
|
'&to_date=$to',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// final url = Uri.parse(
|
// final url = Uri.parse(
|
||||||
// 'http://localhost/nhance_partner_be/dashboard/partnerDashboard?manager_id=$id',
|
// 'http://localhost/nhance_partner_be/dashboard/partnerDashboard?manager_id=$id',
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:nhance_partner/data/utils/toastNotification.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import '../../../../core/responsive/responsive_builder.dart';
|
import '../../../../core/responsive/responsive_builder.dart';
|
||||||
@ -14,14 +15,18 @@ import '../../../providers/userRoleProvider.dart';
|
|||||||
import '../../staff/Enquiry/tabs/tab.dart';
|
import '../../staff/Enquiry/tabs/tab.dart';
|
||||||
import '../../staff/assignStaff.dart';
|
import '../../staff/assignStaff.dart';
|
||||||
|
|
||||||
|
|
||||||
class PartnerDashboard extends ConsumerStatefulWidget {
|
class PartnerDashboard extends ConsumerStatefulWidget {
|
||||||
const PartnerDashboard({super.key});
|
const PartnerDashboard({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<PartnerDashboard> createState() => _DashboardState();
|
ConsumerState<PartnerDashboard> createState() => _PartnerDashboardState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DashboardState extends ConsumerState<PartnerDashboard> {
|
class _PartnerDashboardState extends ConsumerState<PartnerDashboard> {
|
||||||
|
/// ✅ DATE STATE (ONLY FOR PARTNER TAB)
|
||||||
|
DateTime? fromDate;
|
||||||
|
DateTime? toDate;
|
||||||
int selectedIndex = 1;
|
int selectedIndex = 1;
|
||||||
int switcherStatus = 1;
|
int switcherStatus = 1;
|
||||||
late ApiService apiService;
|
late ApiService apiService;
|
||||||
@ -112,6 +117,65 @@ class _DashboardState extends ConsumerState<PartnerDashboard> {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 🔹 DATE PICKER
|
||||||
|
Future<void> pickDate(bool isFrom) async {
|
||||||
|
final picked = await showDatePicker(
|
||||||
|
context: context,
|
||||||
|
initialDate: DateTime.now(),
|
||||||
|
firstDate: DateTime(2022),
|
||||||
|
lastDate: DateTime.now(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (picked != null) {
|
||||||
|
setState(() {
|
||||||
|
if (isFrom) {
|
||||||
|
fromDate = picked;
|
||||||
|
} else {
|
||||||
|
toDate = picked;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// OPTIONAL: reload API with date range
|
||||||
|
// final managerId = ref.read(managerIdProvider);
|
||||||
|
// if (managerId != null) {
|
||||||
|
// getParnterDashBrdList(managerId);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 🔹 DATE PICKER UI
|
||||||
|
Widget headerDatePicker({
|
||||||
|
required String label,
|
||||||
|
DateTime? date,
|
||||||
|
required VoidCallback onTap,
|
||||||
|
}) {
|
||||||
|
return InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
height: 32,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.calendar_today, size: 14, color: Colors.grey),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Text(
|
||||||
|
date == null
|
||||||
|
? label
|
||||||
|
: DateFormat('dd-MM-yyyy').format(date),
|
||||||
|
style: GoogleFonts.inter(fontSize: 11),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> getParnterDashBrdList(id) async {
|
Future<void> getParnterDashBrdList(id) async {
|
||||||
// print('getClaimList called MagId - $managerId - $role');
|
// print('getClaimList called MagId - $managerId - $role');
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -120,10 +184,7 @@ class _DashboardState extends ConsumerState<PartnerDashboard> {
|
|||||||
// dynamic id = widget.policyNumber;
|
// dynamic id = widget.policyNumber;
|
||||||
print('getBusinessDshID - $id');
|
print('getBusinessDshID - $id');
|
||||||
try {
|
try {
|
||||||
final response = await apiService.findPartnerDashboardData(
|
final response = await apiService.findPartnerDashboardData(id,fromDate,toDate);
|
||||||
id,
|
|
||||||
SelctdPartnerbroker,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response['status'] == 'success') {
|
if (response['status'] == 'success') {
|
||||||
final data = response['data'];
|
final data = response['data'];
|
||||||
@ -284,6 +345,38 @@ class _DashboardState extends ConsumerState<PartnerDashboard> {
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onSearch() {
|
||||||
|
final managerId = ref.read(managerIdProvider);
|
||||||
|
|
||||||
|
if (managerId == null) return;
|
||||||
|
|
||||||
|
// OPTIONAL: validation
|
||||||
|
if (fromDate != null && toDate != null && fromDate!.isAfter(toDate!)) {
|
||||||
|
ToastHelper.showWarningToast(context, 'From date cannot be after To date');
|
||||||
|
// ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
// const SnackBar(content: Text('From date cannot be after To date')),
|
||||||
|
// );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔍 Call API with date filter
|
||||||
|
getParnterDashBrdList(managerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onReset() {
|
||||||
|
setState(() {
|
||||||
|
fromDate = null;
|
||||||
|
toDate = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
final managerId = ref.read(managerIdProvider);
|
||||||
|
if (managerId != null) {
|
||||||
|
// ♻️ Reload without date filter
|
||||||
|
getParnterDashBrdList(managerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// final enquiries = ref.watch(enquiriesProvider);
|
// final enquiries = ref.watch(enquiriesProvider);
|
||||||
@ -294,13 +387,53 @@ class _DashboardState extends ConsumerState<PartnerDashboard> {
|
|||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
margin: EdgeInsets.all(10),
|
margin: EdgeInsets.all(0),
|
||||||
// color: Colors.red.shade100,
|
// color: Colors.red.shade100,
|
||||||
// height: MediaQuery.of(context).size.height * 0.75,
|
// height: MediaQuery.of(context).size.height * 0.75,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
scrollDirection: Axis.vertical,
|
scrollDirection: Axis.vertical,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Spacer(),
|
||||||
|
headerDatePicker(
|
||||||
|
label: 'From',
|
||||||
|
date: fromDate,
|
||||||
|
onTap: () => pickDate(true),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
headerDatePicker(
|
||||||
|
label: 'To',
|
||||||
|
date: toDate,
|
||||||
|
onTap: () => pickDate(false),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
|
||||||
|
/// ♻️ RESET
|
||||||
|
actionIcon(
|
||||||
|
icon: Icons.refresh,
|
||||||
|
tooltip: 'Reset',
|
||||||
|
onTap: onReset,
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
|
||||||
|
/// 🔍 SEARCH
|
||||||
|
actionIcon(
|
||||||
|
icon: Icons.search,
|
||||||
|
tooltip: 'Search',
|
||||||
|
onTap: onSearch,
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
if (role == 'manager' || role == 'handler' || role == 'agent')
|
if (role == 'manager' || role == 'handler' || role == 'agent')
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: MediaQuery.of(context).size.height * 0.78,
|
height: MediaQuery.of(context).size.height * 0.78,
|
||||||
@ -543,6 +676,30 @@ class _DashboardState extends ConsumerState<PartnerDashboard> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget actionIcon({
|
||||||
|
required IconData icon,
|
||||||
|
required String tooltip,
|
||||||
|
required VoidCallback onTap,
|
||||||
|
}) {
|
||||||
|
return Tooltip(
|
||||||
|
message: tooltip,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
child: Container(
|
||||||
|
height: 32,
|
||||||
|
width: 32,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFF2E7D6E),
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Icon(icon, size: 16, color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Performance extends StatefulWidget {
|
class Performance extends StatefulWidget {
|
||||||
@ -1028,3 +1185,5 @@ final _chartHeader = GoogleFonts.poppins(
|
|||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user