import 'dart:convert'; import 'dart:math' as math; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:intl/intl.dart'; import 'package:timeago/timeago.dart' as timeago; import 'lat_lng.dart'; import 'place.dart'; import 'uploaded_file.dart'; String? isOneAcliID(String jsonString) { // Converte o JSON em um Map final Map data = jsonDecode(jsonString); // Extrai a lista de locais final List locais = data['locais']; // Filtra os locais onde CLU_STATUS é igual a "A" final List locaisAtivos = locais.where((local) => local['CLU_STATUS'] == 'A').toList(); // Verifica se existe somente um local ativo if (locaisAtivos.length == 1) { return locaisAtivos.first['CLI_ID']; } else { return null; } } String? convertToUppercase(String input) { // recebe uuma string qualquer e retorna ela em uppercase return input.toUpperCase(); } String? uploadFileToBase64(String? uploadFile) { // takes an UploadFile of an image as an argument and returns a base64 string of that image if (uploadFile == null) { return null; } // Converte a string em uma lista de inteiros final List bytes = uploadFile.codeUnits; // Converte os bytes em uma string base64 final String base64String = base64.encode(bytes); return base64String; } String jsonListToStr(List visitorList) { // rece um json list e retorna uma string de $.visitante.VTE_DOCUMENTO separado por virgula String result = ''; for (var visitor in visitorList) { result += '${visitor['VTE_DOCUMENTO']},'; } return result.substring(0, result.length - 1); } List listStrJsonToJsonList( dynamic jsonList, List strList, ) { // Recebe um jsonList e uma stringList como argumento e retorna uma nova jsonList associando cada item List result = []; for (int i = 0; i < jsonList.length; i++) { Map item = jsonList[i]; if (i < strList.length) { item['newField'] = strList[i]; } else { item['newField'] = ''; } result.add(item); } return result; } String strListToStr(List strList) { // recebe uma stringList como argumento e retorna uma str com cada item da strList separado por virgula return strList.join(','); } int extractIdToStr(String str) { // recebe um uma string e retorna um inteiro com o valor entre '_ID:' e a próxima vírgula ',' final idStart = str.indexOf('_ID:') + 4; final idEnd = str.indexOf(',', idStart); final idStr = str.substring(idStart, idEnd); return int.parse(idStr); } String extractDescToStr(String str) { // recebe um uma string e retorna uma string com o valor entre '_DESCRICAO' e a próxima vírgula ',' final startIndex = str.indexOf('_DESCRICAO:') + '_DESCRICAO:'.length; final endIndex = str.indexOf(',', startIndex); return str.substring(startIndex, endIndex); } String jsonToStr(dynamic json) { // recebe um json como parametro, converte-o em string e retorna essa string String jsonString = jsonEncode(json); return jsonString; } Stream getProgressValue() { final startTime = DateTime.now().millisecondsSinceEpoch; final endTime = startTime + 20000; final duration = Duration(milliseconds: 100); return Stream.periodic(duration, (int count) { final currentTime = DateTime.now().millisecondsSinceEpoch; final elapsedTime = currentTime - startTime; final progress = math.max(0.0, 1.0 - (elapsedTime / (endTime - startTime))); return progress; }); }