28 lines
791 B
Dart
28 lines
791 B
Dart
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(String customerNo) async {
|
|
try {
|
|
final response = await _dio.get('/customer/details');
|
|
if (response.statusCode == 200) {
|
|
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()}');
|
|
}
|
|
}
|
|
} |