This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:get/get.dart'; | |
import '../controller/home_controller.dart'; | |
class HomeView extends GetView<HomeController> { | |
const HomeView({super.key}); | |
@override | |
Widget build(BuildContext context) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HomeBindings extends Bindings { | |
@override | |
void dependencies() { | |
Get.lazyPut<HomeController>(() => HomeController()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:dio/dio.dart'; | |
class ApiException implements Exception { | |
ApiException.fromDioError(DioError dioError) { | |
switch (dioError.type) { | |
case DioErrorType.cancel: | |
message = "Request to API server was cancelled"; | |
break; | |
case DioErrorType.connectTimeout: | |
message = "Connection timeout with API server"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HomeController extends GetxController with StateMixin<List<Users>> { | |
final UserApi _userApi = UserApi(); | |
RxList<Users> users = <Users>[].obs; | |
@override | |
void onInit() { | |
super.onInit(); | |
fetchUsers(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserApi { | |
final ApiService _apiService = ApiService(); | |
Future<Response> getUsers() async { | |
try { | |
final Response response = await _apiService.get(AppUrl.users); | |
return response; | |
} catch (e) { | |
rethrow; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserModel { | |
List<Users>? users; | |
int? total; | |
int? skip; | |
int? limit; | |
UserModel({this.users, this.total, this.skip, this.limit}); | |
UserModel.fromJson(Map<String, dynamic> json) { | |
if (json['users'] != null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<Response> post( | |
String url, { | |
data, | |
Map<String, dynamic>? queryParameters, | |
Options? options, | |
CancelToken? cancelToken, | |
ProgressCallback? onSendProgress, | |
ProgressCallback? onReceiveProgress, | |
}) async { | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppUrl { | |
AppUrl._(); | |
// base url | |
static const String baseUrl = "https://dummyjson.com/"; | |
// receiveTimeout | |
static const int receiveTimeout = 15000; | |
// connectTimeout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApiService { | |
ApiService._(); | |
static final _options = BaseOptions( | |
baseUrl: AppUrl.baseUrl, | |
connectTimeout: AppUrl.connectTimeout, | |
receiveTimeout: AppUrl.receiveTimeout, | |
responseType: ResponseType.json, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies: | |
dio: ^4.0.6 | |
get: ^4.6.5 |