feat: add Supabase integration to Flutter and update dependencies
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
const String SUPABASE_URL = 'https://qckndtzudciejpnwqfzt.supabase.co';
|
||||
const String SUPABASE_ANON_KEY = 'sb_secret_2y3a_9qD5nRtZl-41CY-jw_LA-smvxC';
|
||||
119
lib/core/supabase_service.dart
Normal file
119
lib/core/supabase_service.dart
Normal file
@@ -0,0 +1,119 @@
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
final supabaseClient = Supabase.instance.client;
|
||||
|
||||
class RutasService {
|
||||
final SupabaseClient _client = supabaseClient;
|
||||
|
||||
// ── Obtener ruta por ID ──
|
||||
Future<Map<String, dynamic>?> obtenerRuta(String routeId) async {
|
||||
try {
|
||||
final response = await _client
|
||||
.from('rutas')
|
||||
.select('*')
|
||||
.eq('id', routeId)
|
||||
.single();
|
||||
return response;
|
||||
} catch (e) {
|
||||
print('Error obtener_ruta: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Obtener puntos de ruta ──
|
||||
Future<List<Map<String, dynamic>>> obtenerPuntosRuta(String routeId) async {
|
||||
try {
|
||||
final response = await _client
|
||||
.from('puntos_ruta')
|
||||
.select('*')
|
||||
.eq('ruta_id', routeId)
|
||||
.order('orden');
|
||||
return response;
|
||||
} catch (e) {
|
||||
print('Error obtener_puntos_ruta: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// ── Obtener truck status ──
|
||||
Future<Map<String, dynamic>?> obtenerTruckStatus(String routeId) async {
|
||||
try {
|
||||
final response = await _client
|
||||
.from('truck_status')
|
||||
.select('*')
|
||||
.eq('route_id', routeId)
|
||||
.single();
|
||||
return response;
|
||||
} catch (e) {
|
||||
print('Error obtener_truck_status: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Obtener template de notificación ──
|
||||
Future<Map<String, dynamic>?> obtenerTemplate(String triggerEvent) async {
|
||||
try {
|
||||
final response = await _client
|
||||
.from('notification_templates')
|
||||
.select('*')
|
||||
.eq('trigger_event', triggerEvent)
|
||||
.single();
|
||||
return response;
|
||||
} catch (e) {
|
||||
print('Error obtener_template: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Obtener preferencias de usuario ──
|
||||
Future<Map<String, dynamic>?> obtenerPreferencias(String userId) async {
|
||||
try {
|
||||
final response = await _client
|
||||
.from('notification_preferences')
|
||||
.select('*')
|
||||
.eq('user_id', userId)
|
||||
.single();
|
||||
return response;
|
||||
} catch (e) {
|
||||
print('Error obtener_preferencias: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Obtener dirección de usuario ──
|
||||
Future<Map<String, dynamic>?> obtenerDireccion(int addressId) async {
|
||||
try {
|
||||
final response = await _client
|
||||
.from('addresses')
|
||||
.select('*')
|
||||
.eq('id', addressId)
|
||||
.single();
|
||||
return response;
|
||||
} catch (e) {
|
||||
print('Error obtener_direccion: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Guardar notificación ──
|
||||
Future<void> guardarNotificacion({
|
||||
required String tipo,
|
||||
required String routeId,
|
||||
required int addressId,
|
||||
required String mensaje,
|
||||
int? etaMinutos,
|
||||
}) async {
|
||||
try {
|
||||
await _client.from('notificaciones').insert({
|
||||
'tipo': tipo,
|
||||
'ruta_id': routeId,
|
||||
'address_id': addressId,
|
||||
'mensaje': mensaje,
|
||||
'eta_minutos': etaMinutos,
|
||||
'creada_en': DateTime.now().toIso8601String(),
|
||||
});
|
||||
} catch (e) {
|
||||
print('Error guardar_notificacion: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'core/config/supabase_config.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
void main() async { // ← Cambia a async
|
||||
WidgetsFlutterBinding.ensureInitialized(); // ← NUEVA
|
||||
|
||||
await Supabase.initialize( // ← NUEVA (3 líneas)
|
||||
url: SUPABASE_URL,
|
||||
anonKey: SUPABASE_ANON_KEY,
|
||||
);
|
||||
|
||||
runApp(const MyApp()); // ← Esta sí estaba
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user