-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54e5ddc
commit 8d84630
Showing
21 changed files
with
153 additions
and
120 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:get_state/home/controllers/home_controller.dart'; | ||
import 'package:get_state/home/data/home_provider.dart'; | ||
import 'package:get_state/home/data/home_repository.dart'; | ||
import '../controllers/home_controller.dart'; | ||
import '../data/home_provider.dart'; | ||
import '../data/home_repository.dart'; | ||
|
||
class HomeBinding extends Bindings { | ||
@override | ||
void dependencies() { | ||
Get.lazyPut<HomeController>(() { | ||
final homeProvider = HomeProvider(); | ||
final homeRepository = HomeRepository(homeProvider); | ||
return HomeController(homeRepository); | ||
Get.put(Dio()); | ||
Get.put(HomeProvider(dio: Get.find())); | ||
Get.put(HomeRepository(homeProvider: Get.find())); | ||
return HomeController(homeRepository: Get.find()); | ||
}); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,41 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:get_state/home/data/home_model.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'home_model.dart'; | ||
|
||
class HomeProvider { | ||
Future<ApiModel> fetchData() async { | ||
abstract class IHomeProvider { | ||
Future<ApiModel> get(); | ||
Future<ApiModel> post(Map<String, dynamic> data); | ||
Future<ApiModel> put(Map<String, dynamic> data); | ||
Future<ApiModel> delete(int id); | ||
} | ||
|
||
class HomeProvider implements IHomeProvider { | ||
final Dio dio; | ||
|
||
HomeProvider({@required this.dio}); | ||
|
||
Future<ApiModel> get() async { | ||
try { | ||
final response = await Dio().get("https://api.covid19api.com/summary"); | ||
final response = await dio.get("https://api.covid19api.com/summary"); | ||
return ApiModel.fromJson(response.data); | ||
} catch (e) { | ||
print(e.toString()); | ||
return null; | ||
} | ||
} | ||
|
||
@override | ||
Future<ApiModel> post(Map<String, dynamic> data) { | ||
throw UnimplementedError(); | ||
} | ||
|
||
@override | ||
Future<ApiModel> put(Map<String, dynamic> data) { | ||
throw UnimplementedError(); | ||
} | ||
|
||
@override | ||
Future<ApiModel> delete(int id) { | ||
throw UnimplementedError(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import 'package:get_state/home/data/home_provider.dart'; | ||
import 'package:get_state/home/data/home_model.dart'; | ||
import 'home_model.dart'; | ||
import 'home_provider.dart'; | ||
|
||
class HomeRepository { | ||
HomeRepository(this.homeProvider); | ||
HomeRepository({this.homeProvider}); | ||
final HomeProvider homeProvider; | ||
|
||
Future<ApiModel> getData() async { | ||
return homeProvider.fetchData(); | ||
return homeProvider.get(); | ||
} | ||
} |
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
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
12 changes: 6 additions & 6 deletions
12
lib/src/get_interface.dart → lib/src/core/get_interface.dart
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
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
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
Oops, something went wrong.