add user service and update user model for customer details retrieval

This commit is contained in:
2025-06-01 13:02:21 +05:30
parent 713b14ee88
commit faf478a7b0
2 changed files with 69 additions and 13 deletions

View 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()}');
}
}
}