Co-authored-by: eddgranados12 <eddgranados12@users.noreply.github.com>
Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com> Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.github.com> modificacion de las vistas principales para el usuario ciudadano, primer avance para el panel admin
This commit is contained in:
40
recolecta_app/lib/core/api/api_service.dart
Normal file
40
recolecta_app/lib/core/api/api_service.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:recolecta_app/core/storage/secure_storage.dart';
|
||||
|
||||
final apiServiceProvider = Provider<ApiService>((ref) {
|
||||
return ApiService(ref);
|
||||
});
|
||||
|
||||
class ApiService {
|
||||
final Ref _ref;
|
||||
final Dio _dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: 'http://localhost:8000', // O la URL de tu backend
|
||||
),
|
||||
);
|
||||
|
||||
ApiService(this._ref) {
|
||||
_dio.interceptors.add(
|
||||
InterceptorsWrapper(
|
||||
onRequest: (options, handler) async {
|
||||
final token = await _ref
|
||||
.read(secureStorageProvider)
|
||||
.read(key: 'auth_token');
|
||||
if (token != null) {
|
||||
options.headers['Authorization'] = 'Bearer $token';
|
||||
}
|
||||
return handler.next(options);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> updateUser(Map<String, dynamic> data) async {
|
||||
try {
|
||||
await _dio.patch('/users/me', data: data);
|
||||
} on DioException catch (e) {
|
||||
throw e.response?.data['detail'] ?? 'Error de red';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ class UIHouseModel {
|
||||
final String calle;
|
||||
final String colonia;
|
||||
final String? routeId;
|
||||
final double? lat;
|
||||
final double? lng;
|
||||
final int radioAlertaMetros;
|
||||
final bool alertaCercana;
|
||||
final bool alertaMedia;
|
||||
@@ -45,6 +47,8 @@ class UIHouseModel {
|
||||
required this.calle,
|
||||
required this.colonia,
|
||||
this.routeId,
|
||||
this.lat,
|
||||
this.lng,
|
||||
this.radioAlertaMetros = 200,
|
||||
this.alertaCercana = true,
|
||||
this.alertaMedia = false,
|
||||
@@ -59,6 +63,8 @@ class UIHouseModel {
|
||||
String? calle,
|
||||
String? colonia,
|
||||
String? routeId,
|
||||
double? lat,
|
||||
double? lng,
|
||||
int? radioAlertaMetros,
|
||||
bool? alertaCercana,
|
||||
bool? alertaMedia,
|
||||
@@ -71,6 +77,8 @@ class UIHouseModel {
|
||||
calle: calle ?? this.calle,
|
||||
colonia: colonia ?? this.colonia,
|
||||
routeId: routeId ?? this.routeId,
|
||||
lat: lat ?? this.lat,
|
||||
lng: lng ?? this.lng,
|
||||
radioAlertaMetros: radioAlertaMetros ?? this.radioAlertaMetros,
|
||||
alertaCercana: alertaCercana ?? this.alertaCercana,
|
||||
alertaMedia: alertaMedia ?? this.alertaMedia,
|
||||
@@ -86,6 +94,8 @@ class UIHouseModel {
|
||||
calle: json['calle'] as String? ?? '',
|
||||
colonia: json['colonia'] as String? ?? '',
|
||||
routeId: json['route_id'] as String?,
|
||||
lat: (json['lat'] as num?)?.toDouble(),
|
||||
lng: (json['lng'] as num?)?.toDouble(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@ import 'package:recolecta_app/features/home/house_screen.dart';
|
||||
import 'package:recolecta_app/features/alerts/alerts_screen.dart';
|
||||
import 'package:recolecta_app/features/profile/profile_screen.dart';
|
||||
import 'package:recolecta_app/features/feedback/feedback_screen.dart';
|
||||
import 'package:recolecta_app/features/profile/edit_profile_screen.dart';
|
||||
import 'package:recolecta_app/features/separation_guide/screens/category_detail_screen.dart';
|
||||
import 'package:recolecta_app/features/separation_guide/screens/separation_guide_screen.dart';
|
||||
import 'package:recolecta_app/core/services/auth_controller.dart';
|
||||
import '../../features/addresses/add_address_page.dart';
|
||||
import '../../features/admin/screens/admin_dashboard_screen.dart';
|
||||
import '../../features/notifications/notifications_screen.dart';
|
||||
import '../../features/quiz/quiz_screen.dart';
|
||||
@@ -75,6 +77,10 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
path: '/register',
|
||||
builder: (context, state) => const RegisterPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/edit-profile',
|
||||
builder: (context, state) => const EditProfileScreen(),
|
||||
),
|
||||
|
||||
// ── Admin ─────────────────────────────────────────────────────────────
|
||||
ShellRoute(
|
||||
@@ -145,6 +151,10 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
path: '/feedback',
|
||||
builder: (context, state) => const FeedbackScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/add-address',
|
||||
builder: (context, state) => const AddAddressPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/guide',
|
||||
builder: (context, state) => const SeparationGuideScreen(),
|
||||
@@ -165,10 +175,7 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
path: '/notifications',
|
||||
builder: (context, state) => const NotificationsScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/quiz',
|
||||
builder: (context, state) => const QuizScreen(),
|
||||
),
|
||||
GoRoute(path: '/quiz', builder: (context, state) => const QuizScreen()),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
@@ -47,12 +47,25 @@ class AuthController extends AsyncNotifier<AuthState> {
|
||||
required String email,
|
||||
required String phone,
|
||||
required String password,
|
||||
String? addressCalle,
|
||||
String? addressColonia,
|
||||
String? addressLabel,
|
||||
double? addressLat,
|
||||
double? addressLng,
|
||||
}) async {
|
||||
state = const AsyncLoading<AuthState>();
|
||||
try {
|
||||
final session = await ref
|
||||
.read(authServiceProvider)
|
||||
.register(email: email, phone: phone, password: password);
|
||||
final session = await ref.read(authServiceProvider).register(
|
||||
email: email,
|
||||
phone: phone,
|
||||
password: password,
|
||||
addressCalle: addressCalle,
|
||||
addressColonia: addressColonia,
|
||||
addressLabel: addressLabel,
|
||||
addressLat: addressLat,
|
||||
addressLng: addressLng,
|
||||
);
|
||||
|
||||
final authState = AuthState.authenticated(
|
||||
token: session.token,
|
||||
userRole: session.userRole,
|
||||
|
||||
@@ -41,6 +41,11 @@ class AuthService {
|
||||
required String email,
|
||||
required String phone,
|
||||
required String password,
|
||||
String? addressCalle,
|
||||
String? addressColonia,
|
||||
String? addressLabel,
|
||||
double? addressLat,
|
||||
double? addressLng,
|
||||
}) {
|
||||
return _authenticate(
|
||||
path: '/auth/register',
|
||||
@@ -48,6 +53,11 @@ class AuthService {
|
||||
'email': email,
|
||||
'phone': phone,
|
||||
'password': password,
|
||||
if (addressCalle != null) 'address_calle': addressCalle,
|
||||
if (addressColonia != null) 'address_colonia': addressColonia,
|
||||
if (addressLabel != null) 'address_label': addressLabel,
|
||||
if (addressLat != null) 'address_lat': addressLat,
|
||||
if (addressLng != null) 'address_lng': addressLng,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user