testInstalledApps function

Future<void> testInstalledApps()

📱 TESTE DE APLICATIVOS INSTALADOS - Com validação completa

Implementation

Future<void> testInstalledApps() async {
  print('📱 [TEST] ========== TESTE DE APLICATIVOS INSTALADOS ==========');

  try {
    final stopwatch = Stopwatch()..start();

    // Testar método JSON
    print('📱 [TEST] Testando método getInstalledApps()...');
    final apps = await StopouBlocker.getInstalledApps();

    stopwatch.stop();
    final duration = stopwatch.elapsedMilliseconds;

    print('📱 [TEST] ✅ Método funcionou em ${duration}ms');
    print('📱 [TEST] 📊 Total de apps: ${apps.length}');

    // Validar estrutura JSON para FlutterFlow
    if (apps.isNotEmpty) {
      final firstApp = apps.first;
      final hasLabel = firstApp.containsKey('label');
      final hasPackageName = firstApp.containsKey('packageName');
      final hasIcon = firstApp.containsKey('iconBase64');

      print('📱 [TEST] 🔍 Validação estrutura JSON:');
      print('📱 [TEST]   - label: ${hasLabel ? "✅" : "❌"}');
      print('📱 [TEST]   - packageName: ${hasPackageName ? "✅" : "❌"}');
      print('📱 [TEST]   - iconBase64: ${hasIcon ? "✅" : "❌"}');

      if (hasLabel && hasPackageName) {
        print('📱 [TEST] ✅ Estrutura JSON válida para FlutterFlow');
      } else {
        print('📱 [TEST] ❌ Estrutura JSON inválida');
      }

      // Log de alguns exemplos
      final appsToLog = apps.take(3);
      for (int i = 0; i < appsToLog.length; i++) {
        final app = appsToLog.elementAt(i);
        final hasIconLocal = app['iconBase64'] != null ? '🎨' : '🚫';
        print(
            '📱 [TEST] Exemplo ${i + 1}: $hasIconLocal ${app['label']} (${app['packageName']})');
      }
    }

    print('📱 [TEST] ==========================================');
    print('📱 [TEST] ✅ Teste concluído com sucesso!');
  } catch (e) {
    print('📱 [TEST] ❌ Erro no teste: $e');
  }
}