![]() ![]() However, for this article, we’ll use a GET request to make a call to the FishWatch API endpoint. It would have methods for each request type, GET, POST, PUT, PATCH, and DELETE. This service would handle all outbound HTTP requests from our application. Now that we’ve registered each of the dependencies, we can go ahead and fill them up starting with the ApiService. Now, we can go ahead and run the Flutter command to generate all of the necessary files for the setup configuration: flutter pub run build_runner build -delete-conflicting-outputs LazySingleton(classType: FishSpecieService), Import 'package:flutter_share/services/share_service.dart' Import 'package:flutter_share/services/fish_species_service.dart' ![]() Next, register the services as LazySingleton in the dependencies block: import 'package:flutter_share/services/api_service.dart' Also pass in the StackedLogger to the logger parameter. Create an empty class and mark it with the annotation. In this folder, create a new file named app.dart. We’ll use the dependencies block to register our services.Ĭreate a folder called app in the lib directory, which will hold all the configuration details of our application. ![]() The annotation grants us access to two parameters, routes and dependencies. We’ll use the annotation, which comes from the Stacked package. Next, we’ll set up our routes and register the services. Create a file named fish_response_model.dart where we’ll create the FishResponseModel class and the ImageGallery model class: class FishResponseModel However, we only need the name, image, protein content, and quota.Ĭreate a folder named models in the lib directory, which will hold all the models we’ll use. From the FishWatch API documentation, we see that the API returns the name, description, image, and a host of other details. Next, we’ll set up the models for converting the data we receive. Stacked_generator: ^0.5.7 Setting up the models
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |