add user service and update user model for customer details retrieval
This commit is contained in:
28
lib/api/services/customer_service.dart
Normal file
28
lib/api/services/customer_service.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
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()}');
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user