32 lines
825 B
Dart
32 lines
825 B
Dart
import 'dart:convert';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class ApiService {
|
|
final http.Client _client;
|
|
|
|
ApiService({http.Client? client}) : _client = client ?? http.Client();
|
|
|
|
Future<bool> sendScanData(
|
|
String url, {
|
|
required String barcode,
|
|
required String codeType,
|
|
}) async {
|
|
try {
|
|
final response = await _client
|
|
.post(
|
|
Uri.parse(url),
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: jsonEncode({
|
|
'barcode': barcode,
|
|
'code_type': codeType,
|
|
'timestamp': DateTime.now().toUtc().toIso8601String(),
|
|
}),
|
|
)
|
|
.timeout(const Duration(seconds: 5));
|
|
return response.statusCode >= 200 && response.statusCode < 300;
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|