You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.5 KiB
Dart
66 lines
2.5 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
import 'package:test_sa/new_views/common_widgets/app_lazy_loading.dart';
|
|
import 'package:test_sa/service_request_latest/request_detail_provider.dart';
|
|
|
|
class ServiceRequestUtils {
|
|
static double calculateAndAssignWorkingHours({
|
|
required DateTime? startTime,
|
|
required DateTime? endTime,
|
|
required TextEditingController workingHoursController,
|
|
required Function(double) updateModel, // A callback to update the model
|
|
}) {
|
|
print('start date i got is $startTime');
|
|
print('end date i got is $endTime');
|
|
if (startTime != null && endTime != null) {
|
|
Duration difference = endTime.difference(startTime);
|
|
double hours = difference.inMinutes / 60.0; // Calculate hours as a decimal
|
|
workingHoursController.text = hours.toStringAsFixed(1); // Format to 1 decimal places
|
|
updateModel(hours); // Call the function to update the model
|
|
return hours;
|
|
} else {
|
|
return -1; // Indicating invalid input
|
|
}
|
|
}
|
|
|
|
static void getQrCode({required BuildContext context }) async{
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
RequestDetailProvider requestDetailProvider = Provider.of<RequestDetailProvider>(context,listen:false);
|
|
String? base64String = await requestDetailProvider.getQrCode(workOrderId: requestDetailProvider.currentWorkOrder!.data!.requestId ?? 0);
|
|
Navigator.pop(context);
|
|
if (base64String != null) {
|
|
// You have the base64 string, now you can display it
|
|
Uint8List bytes = base64Decode(base64String);
|
|
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
backgroundColor: Colors.white,
|
|
title:context.translation.scanQr.heading6(context).center,
|
|
content: Image.memory(
|
|
bytes, // Displaying the QR code from base64
|
|
fit: BoxFit.contain, // Ensure the image fits well in the dialog
|
|
errorBuilder: (context, error, stackTrace) {
|
|
return const Icon(Icons.error, color: Colors.red);
|
|
},
|
|
),
|
|
|
|
);
|
|
},
|
|
);
|
|
} else {
|
|
print('Failed to get the QR code');
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|