@@ -167,6 +167,49 @@ Future<ApiResponse<Map>> fetchFavorites([
167167 return ApiResponse (error: ApiErrors .error);
168168}
169169
170+ Future <ApiResponse <Map >> fetchTagImages (int tagID, [int page = 0 ]) async {
171+ Map <String , String > query = {
172+ "format" : "json" ,
173+ "method" : "pwg.tags.getImages" ,
174+ "tag_id" : tagID.toString (),
175+ "per_page" : "100" ,
176+ "page" : page.toString (),
177+ };
178+
179+ try {
180+ Response response = await ApiClient .get (queryParameters: query);
181+
182+ if (response.statusCode == 200 ) {
183+ final Map <String , dynamic > result = json.decode (response.data);
184+ if (result['stat' ] == 'fail' ) {
185+ return ApiResponse <Map >(data: {
186+ 'total_count' : 0 ,
187+ 'images' : [],
188+ });
189+ }
190+ final jsonImages = result['result' ]['images' ];
191+ List <ImageModel > images = List <ImageModel >.from (
192+ jsonImages.map ((image) {
193+ image['tags' ] = null ;
194+ return ImageModel .fromJson (image);
195+ }),
196+ );
197+
198+ print (result['result' ]['paging' ]);
199+
200+ return ApiResponse <Map >(data: {
201+ 'total_count' : result['result' ]['paging' ]['total_count' ],
202+ 'images' : images,
203+ });
204+ }
205+ } on DioError catch (e) {
206+ debugPrint ('Fetch tag images: ${e .message }' );
207+ } on Error catch (e) {
208+ debugPrint ('Fetch tag images: ${e .stackTrace }' );
209+ }
210+ return ApiResponse (error: ApiErrors .error);
211+ }
212+
170213Future <String ?> pickDirectoryPath () async {
171214 return await FilePicker .platform.getDirectoryPath ();
172215}
0 commit comments