Merge branch 'master' of bitbucket.org:jubilian/nhance_partner
This commit is contained in:
commit
f3443261f9
File diff suppressed because one or more lines are too long
@ -43,23 +43,6 @@ class ApiService {
|
||||
return _handleResponse(response);
|
||||
}
|
||||
|
||||
// Future<Map<String, dynamic>> _makePostRequest(
|
||||
// Uri url, Map<String, String> body, Map<String, String> headers) async {
|
||||
// final response = await http.post(url, headers: headers, body: body);
|
||||
// return _handleResponse(response);
|
||||
// }
|
||||
//
|
||||
// Future<Map<String, dynamic>> _handleResponse(http.Response response) async {
|
||||
// if (response.statusCode == 200) {
|
||||
// return jsonDecode(response.body);
|
||||
// } else if (response.statusCode == 401) {
|
||||
// await clearLocalStorageAndRedirect();
|
||||
// return {};
|
||||
// } else {
|
||||
// throw Exception('Failed to load data');
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<http.Response> _makeGethttpRequest(
|
||||
Uri url,
|
||||
Map<String, String> headers,
|
||||
@ -176,21 +159,39 @@ class ApiService {
|
||||
}
|
||||
|
||||
// 3. UNAUTHORIZED / FORBIDDEN (The 401/403 Fix)
|
||||
if ((response.statusCode == 401 && body['status'] == 401) ||
|
||||
(response.statusCode == 403 && body['status'] == 403)) {
|
||||
// Perform cleanup
|
||||
await AuthService.clearToken();
|
||||
// if ((response.statusCode == 401 && body['status'] == 401) ||
|
||||
// (response.statusCode == 403 && body['status'] == 403)) {
|
||||
// // Perform cleanup
|
||||
// await AuthService.clearToken();
|
||||
//
|
||||
// // Redirect using global appRouter (avoids context errors)
|
||||
// context.go(AppRoutes.login);
|
||||
//
|
||||
// // Return a structured error so the UI knows why it failed
|
||||
// return {'status': 401, 'message': 'Session expired or invalid'};
|
||||
// }
|
||||
//
|
||||
// if (response.statusCode == 401 || response.statusCode == 403) {
|
||||
// await clearLocalStorageAndRedirect();
|
||||
// return {};
|
||||
// }
|
||||
|
||||
// Redirect using global appRouter (avoids context errors)
|
||||
context.go(AppRoutes.login);
|
||||
final message = (body['message'] ?? body['error'] ?? '')
|
||||
.toString()
|
||||
.toLowerCase();
|
||||
|
||||
// Return a structured error so the UI knows why it failed
|
||||
return {'status': 401, 'message': 'Session expired or invalid'};
|
||||
}
|
||||
// 2️⃣ TOKEN / AUTH FAILURE (message OR status based)
|
||||
final isAuthError =
|
||||
response.statusCode == 401 ||
|
||||
response.statusCode == 403 ||
|
||||
message.contains('token required') ||
|
||||
message.contains('invalid or expired token');
|
||||
|
||||
if (response.statusCode == 401 || response.statusCode == 403) {
|
||||
await clearLocalStorageAndRedirect();
|
||||
return {};
|
||||
if (isAuthError) {
|
||||
await clearLocalStorageAndRedirect(); // handles navigation internally
|
||||
|
||||
// Stop further execution
|
||||
throw Exception('Authentication error');
|
||||
}
|
||||
|
||||
// 4. ALL OTHER ERRORS
|
||||
|
||||
@ -785,6 +785,7 @@ class _AddDialogState extends State<AddDialog> {
|
||||
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
buildUploadDocumentClaims(context),
|
||||
SizedBox(width: 15),
|
||||
@ -813,6 +814,7 @@ class _AddDialogState extends State<AddDialog> {
|
||||
SizedBox(height: 10),
|
||||
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
buildUploadDocumentClaims(context),
|
||||
@ -850,11 +852,11 @@ class _AddDialogState extends State<AddDialog> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Claims Description ", style: _textStyle),
|
||||
// SizedBox(height: 10),
|
||||
SizedBox(height: 10),
|
||||
ThemedFormField(
|
||||
backgroundColor: Color(0xFFEDF6F5),
|
||||
controller: controllers['claimsDesc']!,
|
||||
txtheight: 45,
|
||||
// txtheight: 45,
|
||||
validator: (value) => Validators.requiredField(value, "claimsDesc"),
|
||||
txtwidth: ResponsiveLayout.isMobile(context)
|
||||
? null
|
||||
@ -960,7 +962,7 @@ class _AddDialogState extends State<AddDialog> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Upload Document", style: _textStyle),
|
||||
SizedBox(width: 10),
|
||||
SizedBox(height: 10),
|
||||
ThemedUploadField(
|
||||
backgroundColor: Color(0xFFEDF6F5),
|
||||
hintText: selectedClaimFileNames ?? "Upload Document",
|
||||
@ -1143,8 +1145,8 @@ class _AddDialogState extends State<AddDialog> {
|
||||
txtwidth: ResponsiveLayout.isMobile(context)
|
||||
? null
|
||||
: MediaQuery.of(context).size.width * 0.26,
|
||||
keyboardType: TextInputType.multiline,
|
||||
txtheight: 45,
|
||||
// keyboardType: TextInputType.multiline,
|
||||
// txtheight: 45,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@ -719,6 +719,7 @@ class _BussinessDashboardState extends ConsumerState<BussinessDashboard> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(child: Text('Product-Wise', style: _chartHeader)),
|
||||
Text(
|
||||
|
||||
@ -301,7 +301,7 @@ class _DashboardState extends ConsumerState<PartnerDashboard> {
|
||||
scrollDirection: Axis.vertical,
|
||||
child: Column(
|
||||
children: [
|
||||
if (role == 'manager' || role == 'hanlder')
|
||||
if (role == 'manager' || role == 'handler')
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.78,
|
||||
// ✅ replace Expanded
|
||||
|
||||
@ -353,6 +353,7 @@ class _ProductivityDashboardState extends ConsumerState<ProductivityDashboard> {
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(right: 10),
|
||||
color: Colors.white,
|
||||
|
||||
shadowColor: Colors.black,
|
||||
elevation: 1, // card shadow
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
@ -394,17 +395,20 @@ class _ProductivityDashboardState extends ConsumerState<ProductivityDashboard> {
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: CustomStackedBarChart(
|
||||
labels: staffLabels,
|
||||
labelsId: staffLabelsId,
|
||||
// maxY: (maxPremium * 1.1).ceilToDouble(),
|
||||
maxY: _getSmartMaxValue(),
|
||||
initialRotation: 1,
|
||||
dataList: [],
|
||||
productsList: staffChartData,
|
||||
vehicleTypeNames:
|
||||
staffVehicleTypeNames, // 👈 NEW: Pass vehicle names
|
||||
Container(
|
||||
// color: Colors.amber.shade100,
|
||||
child: Expanded(
|
||||
child: CustomStackedBarChart(
|
||||
labels: staffLabels,
|
||||
labelsId: staffLabelsId,
|
||||
// maxY: (maxPremium * 1.1).ceilToDouble(),
|
||||
maxY: _getSmartMaxValue(),
|
||||
initialRotation: 1,
|
||||
dataList: [],
|
||||
productsList: staffChartData,
|
||||
vehicleTypeNames:
|
||||
staffVehicleTypeNames, // 👈 NEW: Pass vehicle names
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(children: [Expanded(child: legendWidget())]),
|
||||
|
||||
@ -292,7 +292,7 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Start Date', style: _textStyle),
|
||||
Text('Start Date *', style: _textStyle),
|
||||
SizedBox(height: 5),
|
||||
SizedBox(
|
||||
height: 35,
|
||||
@ -323,7 +323,7 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('End Date', style: _textStyle),
|
||||
Text('End Date *', style: _textStyle),
|
||||
SizedBox(height: 5),
|
||||
SizedBox(
|
||||
height: 35,
|
||||
@ -371,7 +371,7 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Broker', style: _textStyle),
|
||||
Text('Broker *', style: _textStyle),
|
||||
SizedBox(height: 5),
|
||||
SizedBox(
|
||||
height: 35,
|
||||
@ -523,7 +523,7 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Referer", style: _textStyle),
|
||||
Text("Referer *", style: _textStyle),
|
||||
SizedBox(height: 5),
|
||||
SizedBox(
|
||||
height: 35,
|
||||
@ -554,9 +554,14 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
|
||||
// },
|
||||
validator: (val) {
|
||||
if (val == null || val.isEmpty) {
|
||||
return "Required";
|
||||
return ""; // 👈 triggers error border, no text
|
||||
}
|
||||
return null;
|
||||
|
||||
// if (val == null || val.isEmpty) {
|
||||
// return "Required";
|
||||
// }
|
||||
// return null;
|
||||
},
|
||||
|
||||
decoratorProps: DropDownDecoratorProps(
|
||||
@ -569,6 +574,7 @@ class _DateFilterRowState extends ConsumerState<DateFilterRowPayout> {
|
||||
color: Colors.black,
|
||||
),
|
||||
filled: true,
|
||||
errorStyle: const TextStyle(height: 0, fontSize: 0),
|
||||
fillColor:
|
||||
Colors.white, // 👈 makes the dropdown input white
|
||||
enabledBorder: OutlineInputBorder(
|
||||
|
||||
@ -783,8 +783,8 @@ class _PayOutScreenState extends ConsumerState<PayOutScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 5),
|
||||
|
||||
// SizedBox(height: 5),
|
||||
if (!isEdit) ...[
|
||||
Container(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
@ -828,6 +828,8 @@ class _PayOutScreenState extends ConsumerState<PayOutScreen> {
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 10),
|
||||
],
|
||||
// Policy Selection
|
||||
Card(
|
||||
|
||||
@ -295,10 +295,13 @@ class policylistState extends ConsumerState<policylist> {
|
||||
}
|
||||
|
||||
Future<void> fetchPolicyExcelReport() async {
|
||||
|
||||
final String fromDate = controllers['startDate']!.text; // "11-01-2025"
|
||||
final String toDate = controllers['endDate']!.text; // "20-01-2025"
|
||||
final response = await apiService.generatePolicyExcel(managerId,fromDate,toDate);
|
||||
final String toDate = controllers['endDate']!.text; // "20-01-2025"
|
||||
final response = await apiService.generatePolicyExcel(
|
||||
managerId,
|
||||
fromDate,
|
||||
toDate,
|
||||
);
|
||||
// Map your controllers and IDs to the API parameters
|
||||
// final String fromDate = controllers['startDate']!.text; // "11-01-2025"
|
||||
// final String toDate = controllers['endDate']!.text; // "20-01-2025"
|
||||
@ -321,7 +324,6 @@ class policylistState extends ConsumerState<policylist> {
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MainLayout(
|
||||
@ -824,7 +826,7 @@ class policylistState extends ConsumerState<policylist> {
|
||||
SizedBox(width: 10),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
showAuditHistoryModal(context,item['id']);
|
||||
showAuditHistoryModal(context, item['id']);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(5.4),
|
||||
@ -859,42 +861,47 @@ class policylistState extends ConsumerState<policylist> {
|
||||
onTap: () {
|
||||
context.push(AppRoutes.policyValidation, extra: item);
|
||||
},
|
||||
child: Container(
|
||||
width: 80, // ⭐ FIXED WIDTH → Equal in both states
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: item['is_data_accuracy_checked'] == '1'
|
||||
? const Color(0xFF2E7D6E)
|
||||
: Colors.redAccent,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceEvenly, // ⭐ Center content
|
||||
children: [
|
||||
Icon(
|
||||
item['is_data_accuracy_checked'] == '1'
|
||||
? Icons.check_circle
|
||||
: Icons.error,
|
||||
size: 12,
|
||||
color: Colors.white,
|
||||
),
|
||||
const SizedBox(width: 1),
|
||||
Text(
|
||||
item['is_data_accuracy_checked'] == '1'
|
||||
? 'Verified'
|
||||
: 'To Verify',
|
||||
style: GoogleFonts.poppins(
|
||||
child: Tooltip(
|
||||
message: item['is_data_accuracy_checked'] == '1'
|
||||
? 'Verified'
|
||||
: 'To Verify',
|
||||
child: Container(
|
||||
width: 80, // ⭐ FIXED WIDTH → Equal in both states
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: item['is_data_accuracy_checked'] == '1'
|
||||
? const Color(0xFF2E7D6E)
|
||||
: Colors.redAccent,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment
|
||||
.spaceEvenly, // ⭐ Center content
|
||||
children: [
|
||||
Icon(
|
||||
item['is_data_accuracy_checked'] == '1'
|
||||
? Icons.check_circle
|
||||
: Icons.error,
|
||||
size: 12,
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
// const SizedBox(width: 1),
|
||||
// Text(
|
||||
// item['is_data_accuracy_checked'] == '1'
|
||||
// ? 'Verified'
|
||||
// : 'To Verify',
|
||||
// style: GoogleFonts.poppins(
|
||||
// color: Colors.white,
|
||||
// fontSize: 10,
|
||||
// fontWeight: FontWeight.w500,
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -1134,7 +1141,10 @@ void showAuditHistoryModal(BuildContext context, dynamic policyId) {
|
||||
|
||||
class AuditHistoryModal extends ConsumerStatefulWidget {
|
||||
final dynamic policyId; // Add this
|
||||
const AuditHistoryModal({super.key, required this.policyId}); // Update constructor
|
||||
const AuditHistoryModal({
|
||||
super.key,
|
||||
required this.policyId,
|
||||
}); // Update constructor
|
||||
|
||||
@override
|
||||
ConsumerState<AuditHistoryModal> createState() => AuditHistoryModalState();
|
||||
@ -1158,11 +1168,15 @@ class AuditHistoryModalState extends ConsumerState<AuditHistoryModal> {
|
||||
setState(() => isLoading = true);
|
||||
try {
|
||||
// Use widget.policyId here!
|
||||
final response = await apiService.fetchAuditHistory(widget.policyId.toString());
|
||||
final response = await apiService.fetchAuditHistory(
|
||||
widget.policyId.toString(),
|
||||
);
|
||||
|
||||
if (response != null && response['status'] == "success") {
|
||||
setState(() {
|
||||
getAuditHistoryData = List<Map<String, dynamic>>.from(response['data']);
|
||||
getAuditHistoryData = List<Map<String, dynamic>>.from(
|
||||
response['data'],
|
||||
);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
@ -1216,53 +1230,89 @@ class AuditHistoryModalState extends ConsumerState<AuditHistoryModal> {
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Expanded(
|
||||
child: isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: getAuditHistoryData.isEmpty
|
||||
? const Center(child: Text("No Audit History Data Found"))
|
||||
: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
dividerColor: Colors.grey.shade200,
|
||||
),
|
||||
child: DataTable(
|
||||
headingRowColor: WidgetStateProperty.all(Color(0xFFF8FAFC)),
|
||||
columnSpacing: 20,
|
||||
columns: [
|
||||
DataColumn(label: Text("Column Name", style: _headerStyle())),
|
||||
DataColumn(label: Text("Message", style: _headerStyle())),
|
||||
DataColumn(label: Text("Changed On", style: _headerStyle())),
|
||||
DataColumn(label: Text("Changed By", style: _headerStyle())),
|
||||
],
|
||||
// Inside your build method's DataTable
|
||||
rows: getAuditHistoryData.map((data) {
|
||||
return DataRow(cells: [
|
||||
DataCell(Text(data['column_name'] ?? "-", style: _cellStyle())),
|
||||
DataCell(
|
||||
SizedBox(
|
||||
width: 300, // Give message more width
|
||||
child: Text(
|
||||
data['message'] ?? "-",
|
||||
style: _cellStyle(),
|
||||
softWrap: true, // Ensure text wraps to next line
|
||||
child: isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: getAuditHistoryData.isEmpty
|
||||
? const Center(child: Text("No Audit History Data Found"))
|
||||
: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Theme(
|
||||
data: Theme.of(
|
||||
context,
|
||||
).copyWith(dividerColor: Colors.grey.shade200),
|
||||
child: DataTable(
|
||||
headingRowColor: WidgetStateProperty.all(
|
||||
Color(0xFFF8FAFC),
|
||||
),
|
||||
columnSpacing: 20,
|
||||
columns: [
|
||||
DataColumn(
|
||||
label: Text(
|
||||
"Column Name",
|
||||
style: _headerStyle(),
|
||||
),
|
||||
),
|
||||
)
|
||||
DataColumn(
|
||||
label: Text("Message", style: _headerStyle()),
|
||||
),
|
||||
DataColumn(
|
||||
label: Text(
|
||||
"Changed On",
|
||||
style: _headerStyle(),
|
||||
),
|
||||
),
|
||||
DataColumn(
|
||||
label: Text(
|
||||
"Changed By",
|
||||
style: _headerStyle(),
|
||||
),
|
||||
),
|
||||
],
|
||||
// Inside your build method's DataTable
|
||||
rows: getAuditHistoryData.map((data) {
|
||||
return DataRow(
|
||||
cells: [
|
||||
DataCell(
|
||||
Text(
|
||||
data['column_name'] ?? "-",
|
||||
style: _cellStyle(),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
SizedBox(
|
||||
width: 300, // Give message more width
|
||||
child: Text(
|
||||
data['message'] ?? "-",
|
||||
style: _cellStyle(),
|
||||
softWrap:
|
||||
true, // Ensure text wraps to next line
|
||||
),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
formatIndianDate(
|
||||
data['changed_on'] ?? "",
|
||||
),
|
||||
style: _cellStyle(),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
data['changed_by'] ?? "-",
|
||||
style: _cellStyle(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
DataCell(Text(
|
||||
formatIndianDate(data['changed_on'] ?? ""),
|
||||
style: _cellStyle(),
|
||||
)),
|
||||
DataCell(Text(data['changed_by'] ?? "-", style: _cellStyle())),
|
||||
]);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -1270,19 +1320,22 @@ class AuditHistoryModalState extends ConsumerState<AuditHistoryModal> {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper styles to keep code clean
|
||||
TextStyle _headerStyle() => GoogleFonts.poppins(
|
||||
fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xFF475569));
|
||||
// Helper styles to keep code clean
|
||||
TextStyle _headerStyle() => GoogleFonts.poppins(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF475569),
|
||||
);
|
||||
|
||||
TextStyle _cellStyle() => GoogleFonts.poppins(
|
||||
fontSize: 11, color: Color(0xFF1E293B));
|
||||
TextStyle _cellStyle() =>
|
||||
GoogleFonts.poppins(fontSize: 11, color: Color(0xFF1E293B));
|
||||
|
||||
String formatIndianDate(String dateStr) {
|
||||
try {
|
||||
DateTime dateTime = DateTime.parse(dateStr);
|
||||
// Format: Day-Month-Year Hour:Minute AM/PM
|
||||
return DateFormat('dd-MM-yyyy hh:mm a').format(dateTime);
|
||||
} catch (e) {
|
||||
return dateStr; // Fallback to original string if parsing fails
|
||||
}
|
||||
}
|
||||
String formatIndianDate(String dateStr) {
|
||||
try {
|
||||
DateTime dateTime = DateTime.parse(dateStr);
|
||||
// Format: Day-Month-Year Hour:Minute AM/PM
|
||||
return DateFormat('dd-MM-yyyy hh:mm a').format(dateTime);
|
||||
} catch (e) {
|
||||
return dateStr; // Fallback to original string if parsing fails
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +36,8 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
// --- Api / state
|
||||
late ApiService apiService;
|
||||
bool isLoading = false;
|
||||
bool isLoadingVehicleType = false;
|
||||
bool isLoadingFuelType = false;
|
||||
dynamic managerId;
|
||||
dynamic userId;
|
||||
|
||||
@ -266,7 +268,6 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (final controller in controllers.values) {
|
||||
@ -289,7 +290,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
|
||||
Future<void> getVehicleType() async {
|
||||
print('getvehicleType called');
|
||||
setState(() => isLoading = true);
|
||||
setState(() => isLoadingVehicleType = true);
|
||||
|
||||
try {
|
||||
final response = await apiService.fetchPolicyMasterDropDown(
|
||||
@ -311,13 +312,13 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
} catch (e) {
|
||||
print('Exception occurred: $e');
|
||||
} finally {
|
||||
setState(() => isLoading = false);
|
||||
setState(() => isLoadingVehicleType = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getFuelType() async {
|
||||
print('getfuelType called');
|
||||
setState(() => isLoading = true);
|
||||
setState(() => isLoadingFuelType = true);
|
||||
|
||||
try {
|
||||
final response = await apiService.fetchPolicyMasterDropDown('fuelType');
|
||||
@ -337,7 +338,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
} catch (e) {
|
||||
print('Exception occurred: $e');
|
||||
} finally {
|
||||
setState(() => isLoading = false);
|
||||
setState(() => isLoadingFuelType = false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -591,16 +592,16 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
// print('_fetchCommision2');
|
||||
|
||||
// 👉 CRITICAL FIX: Set loading to true BEFORE the API call starts
|
||||
setState(() { isLoading = true; });
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
final payload = buildCommissionPayload();
|
||||
debugPrint('Payload in fetchCommission: $payload');
|
||||
final result = await apiService.calculateCommissionRequest(payload);
|
||||
debugPrint('Result in fetchCommission: $result');
|
||||
|
||||
|
||||
if (result != null && result['status'] == 'success') {
|
||||
if (!mounted) return;
|
||||
// setState(() => isLoading = false);
|
||||
@ -613,12 +614,16 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
isLoading = false; // Stop loading
|
||||
if (commissionAmount != null) {
|
||||
// Update controller so the Confirm button becomes active
|
||||
controllers["commission_amount"]?.text =
|
||||
double.parse(commissionAmount.toString()).toStringAsFixed(2);
|
||||
controllers["commission_amount"]?.text = double.parse(
|
||||
commissionAmount.toString(),
|
||||
).toStringAsFixed(2);
|
||||
}
|
||||
});
|
||||
|
||||
ToastHelper.showSuccessToast(context, "Commission calculated successfully");
|
||||
ToastHelper.showSuccessToast(
|
||||
context,
|
||||
"Commission calculated successfully",
|
||||
);
|
||||
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// // Now safe to do navigation + provider updates
|
||||
@ -728,7 +733,10 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text("Vehicle Type", style: TextStyle(fontWeight: FontWeight.w500)),
|
||||
Text(
|
||||
"Vehicle Type",
|
||||
style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 11),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
DropdownSearch<String>(
|
||||
key: dropDownKey,
|
||||
@ -745,7 +753,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
|
||||
validator: (val) {
|
||||
if (val == null || val.isEmpty) {
|
||||
return "Required";
|
||||
return ""; // 👈 triggers error border, no text
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@ -831,7 +839,10 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Fuel Type ", style: TextStyle(fontWeight: FontWeight.w500)),
|
||||
Text(
|
||||
"Fuel Type ",
|
||||
style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 11),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
DropdownSearch<String>(
|
||||
key: dropDownKeyFuel,
|
||||
@ -848,7 +859,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
|
||||
validator: (val) {
|
||||
if (val == null || val.isEmpty) {
|
||||
return "Required";
|
||||
return ""; // 👈 triggers error border, no text
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@ -944,12 +955,12 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
color: Color(0xFF2E7D6E),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(icon, size: 16, color: Colors.white),
|
||||
child: Icon(icon, size: 12, color: Colors.white),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
|
||||
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -968,7 +979,10 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: const TextStyle(fontWeight: FontWeight.w500)),
|
||||
Text(
|
||||
label,
|
||||
style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 11),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
TextFormField(
|
||||
controller: controller,
|
||||
@ -976,9 +990,9 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
readOnly: readOnly,
|
||||
onTap: onTap,
|
||||
inputFormatters: inputFormatters, // 👈 USE HERE
|
||||
validator: (value) {
|
||||
if (required && (value == null || value.trim().isEmpty)) {
|
||||
return "$label is required";
|
||||
validator: (val) {
|
||||
if (val == null || val.isEmpty) {
|
||||
return ""; // 👈 triggers error border, no text
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@ -1026,10 +1040,16 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
// (controllers['commission_amount']?.text.isEmpty ?? true)
|
||||
// ? null
|
||||
// : _save,
|
||||
onPressed: (
|
||||
widget.item?['is_data_accuracy_checked']?.toString() == '0' &&
|
||||
((double.tryParse(controllers["commission_amount"]?.text ?? '0') ?? 0).floor() >= 1)
|
||||
)
|
||||
onPressed:
|
||||
(widget.item?['is_data_accuracy_checked']?.toString() ==
|
||||
'0' &&
|
||||
((double.tryParse(
|
||||
controllers["commission_amount"]?.text ??
|
||||
'0',
|
||||
) ??
|
||||
0)
|
||||
.floor() >=
|
||||
1))
|
||||
? _save
|
||||
: null,
|
||||
style: ElevatedButton.styleFrom(
|
||||
@ -1045,8 +1065,8 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
),
|
||||
child: Text(
|
||||
'Confirm Data Accuracy ',
|
||||
// '(${controllers["commission_amount"]?.text ?? '0'} | '
|
||||
// '${widget.item?['is_data_accuracy_checked'] ?? '0'})',
|
||||
// '(${controllers["commission_amount"]?.text ?? '0'} | '
|
||||
// '${widget.item?['is_data_accuracy_checked'] ?? '0'})',
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
@ -1162,7 +1182,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const Text(
|
||||
'Original Policy Document',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
@ -1268,7 +1288,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Policy Number',
|
||||
'Policy Number *',
|
||||
controllers['policyNumber']!,
|
||||
required: true,
|
||||
),
|
||||
@ -1276,7 +1296,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Insured Name',
|
||||
'Insured Name *',
|
||||
controllers['insuredName']!,
|
||||
required: true,
|
||||
),
|
||||
@ -1287,7 +1307,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Issued Date',
|
||||
'Issued Date *',
|
||||
controllers['issuedDate']!,
|
||||
readOnly: true,
|
||||
required: true,
|
||||
@ -1300,7 +1320,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Start Date',
|
||||
'Start Date *',
|
||||
controllers['startDate']!,
|
||||
|
||||
readOnly: true,
|
||||
@ -1314,7 +1334,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'End Date',
|
||||
'End Date *',
|
||||
controllers['endDate']!,
|
||||
readOnly: true,
|
||||
required: true,
|
||||
@ -1330,7 +1350,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Premium Amount',
|
||||
'Premium Amount *',
|
||||
controllers['premiumAmount']!,
|
||||
|
||||
required: true,
|
||||
@ -1345,7 +1365,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Remarks',
|
||||
'Remarks *',
|
||||
required: false,
|
||||
controllers['remarks']!,
|
||||
),
|
||||
@ -1357,7 +1377,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
const SizedBox(height: 7),
|
||||
|
||||
// Tax Details
|
||||
Card(
|
||||
@ -1373,7 +1393,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_sectionHeader(
|
||||
'Tax / Cover Details',
|
||||
'Tax / Cover Details *',
|
||||
icon: Icons.attach_money,
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
@ -1381,7 +1401,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'TP',
|
||||
'TP *',
|
||||
controllers['tp']!,
|
||||
required: true,
|
||||
keyboardType:
|
||||
@ -1395,7 +1415,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'OD',
|
||||
'OD *',
|
||||
controllers['od']!,
|
||||
required: true,
|
||||
keyboardType:
|
||||
@ -1409,7 +1429,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'PA',
|
||||
'PA *',
|
||||
controllers['pa']!,
|
||||
required: true,
|
||||
keyboardType:
|
||||
@ -1426,7 +1446,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'CGST',
|
||||
'CGST *',
|
||||
controllers['cgst']!,
|
||||
required: true,
|
||||
keyboardType:
|
||||
@ -1440,7 +1460,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'SGST',
|
||||
'SGST *',
|
||||
controllers['sgst']!,
|
||||
required: true,
|
||||
keyboardType:
|
||||
@ -1454,7 +1474,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'IGST',
|
||||
'IGST *',
|
||||
controllers['igst']!,
|
||||
required: true,
|
||||
keyboardType:
|
||||
@ -1472,7 +1492,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
const SizedBox(height: 7),
|
||||
|
||||
// Vehicle Details
|
||||
Card(
|
||||
@ -1497,7 +1517,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'RTO State Name',
|
||||
'RTO State Name *',
|
||||
controllers['rtoStateCode']!,
|
||||
required: true,
|
||||
),
|
||||
@ -1505,7 +1525,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'RTO City Code',
|
||||
'RTO City Code *',
|
||||
controllers['rtoCityCode']!,
|
||||
required: true,
|
||||
keyboardType:
|
||||
@ -1517,7 +1537,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Weight',
|
||||
'Weight *',
|
||||
controllers['weight']!,
|
||||
required: true,
|
||||
keyboardType:
|
||||
@ -1541,7 +1561,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Date of Registration',
|
||||
'Date of Registration *',
|
||||
controllers['dateOfRegistration']!,
|
||||
required: true,
|
||||
readOnly: true,
|
||||
@ -1554,7 +1574,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Year of Manufacture',
|
||||
'Year of Manufacture *',
|
||||
controllers['yearOfManufacture']!,
|
||||
required: true,
|
||||
keyboardType:
|
||||
@ -1569,7 +1589,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Engine No',
|
||||
'Engine No *',
|
||||
controllers['engineNo']!,
|
||||
required: true,
|
||||
),
|
||||
@ -1577,7 +1597,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Chassis No',
|
||||
'Chassis No *',
|
||||
controllers['chassisNo']!,
|
||||
required: true,
|
||||
),
|
||||
@ -1586,7 +1606,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
Expanded(
|
||||
child: Expanded(
|
||||
child: _buildInput(
|
||||
'Make',
|
||||
'Make *',
|
||||
controllers['make']!,
|
||||
required: true,
|
||||
),
|
||||
@ -1598,7 +1618,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Model',
|
||||
'Model *',
|
||||
controllers['model']!,
|
||||
required: true,
|
||||
),
|
||||
@ -1606,7 +1626,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Cubic Capacity',
|
||||
'Cubic Capacity *',
|
||||
controllers['cubicCapacity']!,
|
||||
required: true,
|
||||
keyboardType:
|
||||
@ -1634,8 +1654,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
const SizedBox(height: 7),
|
||||
|
||||
// Broker Details
|
||||
Card(
|
||||
@ -1659,7 +1678,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Broker Name',
|
||||
'Broker Name *',
|
||||
controllers['broker_name']!,
|
||||
required: true,
|
||||
),
|
||||
@ -1667,7 +1686,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _buildInput(
|
||||
'Commission Amount',
|
||||
'Commission Amount *',
|
||||
controllers['commission_amount']!,
|
||||
// required: true,
|
||||
keyboardType:
|
||||
@ -1681,24 +1700,36 @@ class _policyValidationState extends ConsumerState<policyValidation> {
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end, // Pushes children to the right
|
||||
mainAxisAlignment: MainAxisAlignment
|
||||
.end, // Pushes children to the right
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: (widget.item?['is_data_accuracy_checked'] == '1' || isLoading)
|
||||
onPressed:
|
||||
(widget.item?['is_data_accuracy_checked'] ==
|
||||
'1' ||
|
||||
isLoading)
|
||||
? null // Disable if already checked or currently loading
|
||||
: _fetchCommision,
|
||||
child: Text(isLoading ? "Calculating..." : "Calculate",
|
||||
child: Text(
|
||||
isLoading
|
||||
? "Calculating..."
|
||||
: "Calculate",
|
||||
style: TextStyle(
|
||||
color: (widget.item?['is_data_accuracy_checked'] == '1' || isLoading)
|
||||
color:
|
||||
(widget.item?['is_data_accuracy_checked'] ==
|
||||
'1' ||
|
||||
isLoading)
|
||||
? Colors.grey
|
||||
: const Color(0xFF2E7D6E),
|
||||
fontWeight: FontWeight.bold,
|
||||
)
|
||||
: const Color(
|
||||
0xFF2E7D6E,
|
||||
),
|
||||
fontWeight:
|
||||
FontWeight.bold,
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
],
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@ -94,6 +94,24 @@ class _CustomBarChartState extends ConsumerState<CustomBarChart> {
|
||||
}
|
||||
|
||||
String compactNumber(num value) {
|
||||
if (value >= 10000000) {
|
||||
return '${(value / 10000000).toStringAsFixed(1).replaceAll('.0', '')}Cr';
|
||||
} else if (value >= 1000000) {
|
||||
return '${(value / 1000000).toStringAsFixed(1).replaceAll('.0', '')}M';
|
||||
} else if (value >= 1000) {
|
||||
return '${(value / 1000).toStringAsFixed(1).replaceAll('.0', '')}K';
|
||||
} else if (value >= 1) {
|
||||
// 👇 remove .0 ONLY when it's an integer
|
||||
return value % 1 == 0
|
||||
? value.toInt().toString()
|
||||
: value.toStringAsFixed(1);
|
||||
} else {
|
||||
// 👇 keep decimals for small values
|
||||
return value == 0 ? '0' : value.toStringAsFixed(1);
|
||||
}
|
||||
}
|
||||
|
||||
String compactNumberToolTip(num value) {
|
||||
if (value >= 10000000) {
|
||||
return '${(value / 10000000).toStringAsFixed(1).replaceAll('.0', '')}Cr';
|
||||
} else if (value >= 1000000) {
|
||||
@ -187,7 +205,7 @@ class _CustomBarChartState extends ConsumerState<CustomBarChart> {
|
||||
// rod.toY.round(),
|
||||
// );
|
||||
|
||||
final formattedValue = compactNumber(rod.toY);
|
||||
final formattedValue = compactNumberToolTip(rod.toY);
|
||||
return BarTooltipItem(formattedValue, textStyle);
|
||||
// return BarTooltipItem('${rod.toY.round()}', textStyle);
|
||||
},
|
||||
|
||||
@ -85,6 +85,7 @@ class _CustomBarChartState extends ConsumerState<CustomBarChartHorizontal> {
|
||||
// BarChartRodData(toY: 2, color: Colors.orange.shade300, width: 6),
|
||||
BarChartRodData(
|
||||
toY: value2,
|
||||
// toY: value2,
|
||||
color: const Color(0xFFA5E4E1),
|
||||
// color: Colors.orange.shade300,
|
||||
width: 10,
|
||||
|
||||
@ -60,12 +60,34 @@ class _CustomStackedBarChartState extends ConsumerState<CustomStackedBarChart> {
|
||||
});
|
||||
}
|
||||
|
||||
String compactNumber(num value) {
|
||||
if (value >= 10000000) {
|
||||
return '${(value / 10000000).toStringAsFixed(1).replaceAll('.0', '')}Cr';
|
||||
} else if (value >= 1000000) {
|
||||
return '${(value / 1000000).toStringAsFixed(1).replaceAll('.0', '')}M';
|
||||
} else if (value >= 1000) {
|
||||
return '${(value / 1000).toStringAsFixed(1).replaceAll('.0', '')}K';
|
||||
} else if (value >= 1) {
|
||||
// 👇 remove .0 ONLY when it's an integer
|
||||
return value % 1 == 0
|
||||
? value.toInt().toString()
|
||||
: value.toStringAsFixed(1);
|
||||
} else {
|
||||
// 👇 keep decimals for small values
|
||||
return value == 0 ? '0' : value.toStringAsFixed(1);
|
||||
}
|
||||
}
|
||||
|
||||
// else {
|
||||
// return value.toInt().toString();
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final maxY = widget.maxY <= 0 ? 100.0 : widget.maxY;
|
||||
|
||||
return AspectRatio(
|
||||
aspectRatio: 1.6,
|
||||
aspectRatio: 4,
|
||||
child: BarChart(
|
||||
BarChartData(
|
||||
alignment: BarChartAlignment.spaceAround,
|
||||
@ -110,7 +132,7 @@ class _CustomStackedBarChartState extends ConsumerState<CustomStackedBarChart> {
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
showTitles: true,
|
||||
reservedSize: 56,
|
||||
reservedSize: 130,
|
||||
getTitlesWidget: (value, meta) {
|
||||
final i = value.toInt();
|
||||
if (i < 0 || i >= widget.labels.length) {
|
||||
@ -124,7 +146,7 @@ class _CustomStackedBarChartState extends ConsumerState<CustomStackedBarChart> {
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
textAlign: TextAlign.end,
|
||||
),
|
||||
);
|
||||
},
|
||||
@ -140,7 +162,8 @@ class _CustomStackedBarChartState extends ConsumerState<CustomStackedBarChart> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 3.0),
|
||||
child: Text(
|
||||
value.toInt().toString(),
|
||||
compactNumber(value),
|
||||
// value.toInt().toString(),
|
||||
textAlign: TextAlign.end,
|
||||
style: GoogleFonts.inter(fontSize: 10),
|
||||
),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user