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:flutter/material.dart';
|
||||||
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
|
import 'core/config/supabase_config.dart';
|
||||||
|
|
||||||
void main() {
|
void main() async { // ← Cambia a async
|
||||||
runApp(const MyApp());
|
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 {
|
class MyApp extends StatelessWidget {
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ dependencies:
|
|||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.8
|
cupertino_icons: ^1.0.8
|
||||||
|
supabase_flutter: ^2.5.0
|
||||||
|
riverpod: ^2.6.1
|
||||||
|
dio: ^5.3.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user