From 218ca09e4ebf7a9731f14c6b0bc359cfe064da5b Mon Sep 17 00:00:00 2001 From: Hareesh-Nandigrama Date: Sat, 29 Jul 2023 17:11:20 +0530 Subject: [PATCH] necessary token passed for unnecessary image api --- lib/widgets/buy_sell/buy_tile.dart | 40 +++++++++++++------- lib/widgets/buy_sell/details_dialog.dart | 31 +++++++++++----- lib/widgets/lostfound/ads_tile.dart | 37 +++++++++++++------ lib/widgets/lostfound/lost_found_tile.dart | 43 ++++++++++++++-------- 4 files changed, 101 insertions(+), 50 deletions(-) diff --git a/lib/widgets/buy_sell/buy_tile.dart b/lib/widgets/buy_sell/buy_tile.dart index cea0ecf2..2b42fe3b 100644 --- a/lib/widgets/buy_sell/buy_tile.dart +++ b/lib/widgets/buy_sell/buy_tile.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:onestop_dev/functions/food/rest_frame_builder.dart'; import 'package:onestop_dev/globals/my_colors.dart'; import 'package:onestop_dev/globals/my_fonts.dart'; +import '../../functions/utility/auth_user_helper.dart'; +import '../../globals/endpoints.dart'; import 'details_dialog.dart'; class BuyTile extends StatelessWidget { @@ -75,20 +77,30 @@ class BuyTile extends StatelessWidget { ), ), ), - Expanded( - flex: 4, - child: ClipRRect( - borderRadius: const BorderRadius.only( - topRight: Radius.circular(21), - bottomRight: Radius.circular(21)), - child: Image.network( - model.imageURL, - fit: BoxFit.cover, - cacheWidth: 100, - frameBuilder: restaurantTileFrameBuilder, - errorBuilder: (_, __, ___) => Container(), - ), - ), + FutureBuilder( + future: AuthUserHelpers.getAccessToken(), + builder: (context, snapshot) { + if(snapshot.hasError || !snapshot.hasData) + { + return Container(); + } + return Expanded( + flex: 4, + child: ClipRRect( + borderRadius: const BorderRadius.only( + topRight: Radius.circular(21), + bottomRight: Radius.circular(21)), + child: Image.network( + model.imageURL, + fit: BoxFit.cover, + cacheWidth: 100, + headers: {'Content-Type': 'application/json', 'security-key': Endpoints.apiSecurityKey, 'Authorization': "Bearer ${snapshot.data}"}, + frameBuilder: restaurantTileFrameBuilder, + errorBuilder: (_, __, ___) => Container(), + ), + ), + ); + } ), ], ), diff --git a/lib/widgets/buy_sell/details_dialog.dart b/lib/widgets/buy_sell/details_dialog.dart index e2c575e6..091c3678 100644 --- a/lib/widgets/buy_sell/details_dialog.dart +++ b/lib/widgets/buy_sell/details_dialog.dart @@ -8,6 +8,9 @@ import 'package:onestop_dev/models/buy_sell/sell_model.dart'; import 'package:onestop_dev/models/lostfound/found_model.dart'; import 'package:onestop_dev/widgets/lostfound/claim_call_button.dart'; +import '../../functions/utility/auth_user_helper.dart'; +import '../../globals/endpoints.dart'; + void detailsDialogBox(context, dynamic model, [parentContext]) { final screenWidth = MediaQuery.of(context).size.width; final screenHeight = MediaQuery.of(context).size.height; @@ -95,15 +98,25 @@ void detailsDialogBox(context, dynamic model, [parentContext]) { constraints: BoxConstraints( maxHeight: screenHeight * 0.3, maxWidth: screenWidth - 30), - child: SingleChildScrollView( - child: Image.network( - model.imageURL, - fit: BoxFit.cover, - frameBuilder: restaurantTileFrameBuilder, - width: screenWidth - 30, - cacheWidth: (screenWidth - 30).round(), - errorBuilder: (_, __, ___) => Container(), - ), + child: FutureBuilder( + future: AuthUserHelpers.getAccessToken(), + builder: (context, snapshot) { + if(snapshot.hasError || !snapshot.hasData) + { + return Container(); + } + return SingleChildScrollView( + child: Image.network( + model.imageURL, + fit: BoxFit.cover, + frameBuilder: restaurantTileFrameBuilder, + width: screenWidth - 30, + headers: {'Content-Type': 'application/json', 'security-key': Endpoints.apiSecurityKey, 'Authorization': "Bearer ${snapshot.data}"}, + cacheWidth: (screenWidth - 30).round(), + errorBuilder: (_, __, ___) => Container(), + ), + ); + } ), ), ), diff --git a/lib/widgets/lostfound/ads_tile.dart b/lib/widgets/lostfound/ads_tile.dart index 856340f9..27d75f48 100644 --- a/lib/widgets/lostfound/ads_tile.dart +++ b/lib/widgets/lostfound/ads_tile.dart @@ -9,6 +9,9 @@ import 'package:onestop_dev/models/lostfound/lost_model.dart'; import 'package:onestop_dev/services/api.dart'; import 'package:onestop_dev/widgets/buy_sell/details_dialog.dart'; +import '../../functions/utility/auth_user_helper.dart'; +import '../../globals/endpoints.dart'; + class MyAdsTile extends StatefulWidget { // ignore: prefer_typing_uninitialized_variables final model; @@ -116,18 +119,28 @@ class _MyAdsTileState extends State { ), ), ), - Expanded( - flex: 4, - child: ClipRRect( - borderRadius: const BorderRadius.only( - topRight: Radius.circular(21), - bottomRight: Radius.circular(21)), - child: Image.network(widget.model.imageURL, - cacheWidth: 100, - fit: BoxFit.cover, - errorBuilder: (_, __, ___) => Container(), - frameBuilder: restaurantTileFrameBuilder), - ), + FutureBuilder( + future: AuthUserHelpers.getAccessToken(), + builder: (context, snapshot) { + if(snapshot.hasError || !snapshot.hasData) + { + return Container(); + } + return Expanded( + flex: 4, + child: ClipRRect( + borderRadius: const BorderRadius.only( + topRight: Radius.circular(21), + bottomRight: Radius.circular(21)), + child: Image.network(widget.model.imageURL, + cacheWidth: 100, + fit: BoxFit.cover, + errorBuilder: (_, __, ___) => Container(), + headers: {'Content-Type': 'application/json', 'security-key': Endpoints.apiSecurityKey, 'Authorization': "Bearer ${snapshot.data}"}, + frameBuilder: restaurantTileFrameBuilder), + ), + ); + } ), ], ), diff --git a/lib/widgets/lostfound/lost_found_tile.dart b/lib/widgets/lostfound/lost_found_tile.dart index 23e7819c..3e17c817 100644 --- a/lib/widgets/lostfound/lost_found_tile.dart +++ b/lib/widgets/lostfound/lost_found_tile.dart @@ -6,6 +6,9 @@ import 'package:onestop_dev/models/lostfound/found_model.dart'; import 'package:onestop_dev/widgets/buy_sell/details_dialog.dart'; import 'package:timeago/timeago.dart' as timeago; +import '../../functions/utility/auth_user_helper.dart'; +import '../../globals/endpoints.dart'; + class LostFoundTile extends StatefulWidget { final dynamic currentModel; final BuildContext? parentContext; @@ -84,21 +87,31 @@ class _LostFoundTileState extends State { ), ), ), - ConstrainedBox( - constraints: const BoxConstraints(maxHeight: 105, maxWidth: 135), - child: ClipRRect( - borderRadius: const BorderRadius.only( - topRight: Radius.circular(21), - bottomRight: Radius.circular(21)), - child: Image.network( - widget.currentModel.compressedImageURL, - width: screenWidth * 0.35, - cacheWidth: (screenWidth * 0.35).round(), - fit: BoxFit.cover, - frameBuilder: restaurantTileFrameBuilder, - errorBuilder: (_, __, ___) => Container(), - ), - ), + FutureBuilder( + future: AuthUserHelpers.getAccessToken(), + builder: (context, snapshot) { + if(snapshot.hasError || !snapshot.hasData) + { + return Container(); + } + return ConstrainedBox( + constraints: const BoxConstraints(maxHeight: 105, maxWidth: 135), + child: ClipRRect( + borderRadius: const BorderRadius.only( + topRight: Radius.circular(21), + bottomRight: Radius.circular(21)), + child: Image.network( + widget.currentModel.compressedImageURL, + width: screenWidth * 0.35, + cacheWidth: (screenWidth * 0.35).round(), + fit: BoxFit.cover, + frameBuilder: restaurantTileFrameBuilder, + errorBuilder: (_, __, ___) => Container(), + headers: {'Content-Type': 'application/json', 'security-key': Endpoints.apiSecurityKey, 'Authorization': "Bearer ${snapshot.data}"}, + ), + ), + ); + } ) ], ),