Language Changes
This commit is contained in:
31
lib/api/services/user_service.dart
Normal file
31
lib/api/services/user_service.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:kmobile/data/models/user.dart';
|
||||
|
||||
class UserService {
|
||||
final Dio _dio;
|
||||
UserService(this._dio);
|
||||
|
||||
Future<List<User>> getUserDetails() async {
|
||||
try {
|
||||
final response = await _dio.get('/api/customer/details');
|
||||
if (response.statusCode == 200) {
|
||||
log('Response: ${response.data}');
|
||||
return (response.data as List)
|
||||
.map((user) => User.fromJson(user))
|
||||
.toList();
|
||||
} else {
|
||||
throw Exception('Failed to load customer details');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e.toString());
|
||||
}
|
||||
throw Exception('Network error: ${e.message}');
|
||||
} catch (e) {
|
||||
throw Exception('Unexpected error: ${e.toString()}');
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user