diff --git a/lib/screens/products/liked_list_page.dart b/lib/screens/products/liked_list_page.dart index d2b01ee..c65a5c3 100644 --- a/lib/screens/products/liked_list_page.dart +++ b/lib/screens/products/liked_list_page.dart @@ -3,12 +3,11 @@ import 'package:flutter/widgets.dart'; // import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:intl/intl.dart'; import 'package:saphy/models/product.dart'; +import 'package:saphy/service/api_service.dart'; import 'package:saphy/service/authentication/secure_storage.dart'; -import 'package:saphy/utils/textstyles.dart'; import 'package:saphy/widgets/product_card.dart'; import 'package:saphy/utils/colors.dart'; import 'package:saphy/widgets/app_bar.dart'; -import 'package:dio/dio.dart'; class LikedListPage extends StatefulWidget { const LikedListPage({super.key}); @@ -23,18 +22,17 @@ class _LikedListPageState extends State { int cnt = 0; Future> getProducts() async { - final dio = Dio(); - String? accessToken = await readAccessToken(); + String token = await readJwt(); + token = token.toString().split(" ")[2]; try { - final response = await dio.get( - 'https://saphy.site/item-wishes/', - options: Options( - headers: { - 'Authorization': 'Bearer $accessToken', // 필요한 헤더 추가 - }, - ), + final response = await APIService.instance.request( + 'https://saphy.site/item-wishes?type=ALL', + DioMethod.get, + contentType: 'application/json', + token: "Bearer $token", ); + if (response.statusCode == 200) { final data = response.data as Map; if (data['results'] != null) { diff --git a/lib/screens/products/product_detail_page.dart b/lib/screens/products/product_detail_page.dart index 5fc1379..cb9df63 100644 --- a/lib/screens/products/product_detail_page.dart +++ b/lib/screens/products/product_detail_page.dart @@ -8,6 +8,7 @@ import 'package:saphy/utils/colors.dart'; import 'package:saphy/utils/number_format.dart'; import 'package:saphy/utils/textstyles.dart'; import 'package:saphy/models/product.dart'; +import 'package:shared_preferences/shared_preferences.dart'; class ProductDetail extends StatefulWidget { final Product product; @@ -20,11 +21,23 @@ class ProductDetail extends StatefulWidget { class _ProductDetailState extends State { Product? productDetail; bool isWished = false; + late SharedPreferences wished; + + Future initWishes() async { + wished = await SharedPreferences.getInstance(); + final wishedList = wished.getBool(widget.product.id.toString()); + if (wishedList != null) { + setState(() { + isWished = true; + }); + } else {} + } @override void initState() { super.initState(); loadProduct(); + initWishes(); } Future loadProduct() async { @@ -82,8 +95,6 @@ class _ProductDetailState extends State { token = token.toString().split(" ")[2]; if (!isWished) { - // 아이템을 찜하는 POST 요청 - final response = await APIService.instance.request( 'https://saphy.site/item-wishes?itemId=${widget.product.id}', DioMethod.post, @@ -92,9 +103,9 @@ class _ProductDetailState extends State { ); if (response.statusCode == 200) { - // 요청이 성공적으로 처리된 경우 + await wished.setBool(widget.product.id.toString(), true); setState(() { - isWished = true; // 아이템이 찜 상태로 변경 + isWished = true; }); } } else { @@ -106,6 +117,7 @@ class _ProductDetailState extends State { ); if (response.statusCode == 200) { + await wished.setBool(widget.product.id.toString(), false); setState(() { isWished = false; // 아이템이 찜 해제 상태로 변경 }); diff --git a/pubspec.lock b/pubspec.lock index a0f31bb..2cf0a2b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -716,42 +716,42 @@ packages: dependency: transitive description: name: kakao_flutter_sdk_auth - sha256: "43b81bb90d0e01516d321ab3cedc32303f661f115c564489c0fcc4e4a065c777" + sha256: "686996c63c7e006ccf9a0bdfee5307465d7ae134d2f1ae2b4a06c597604689bc" url: "https://pub.dev" source: hosted - version: "1.9.2" + version: "1.9.6" kakao_flutter_sdk_common: dependency: transitive description: name: kakao_flutter_sdk_common - sha256: "0e3ffd97fa35386d6fabe854cb4c5799b303c75b25f15ce4ec10163d87a5caa5" + sha256: "698d5f63d15438ad47af3baf0815fd30dfcacfa76640e96e5a18fc8504f25bde" url: "https://pub.dev" source: hosted - version: "1.9.2" + version: "1.9.6" kakao_flutter_sdk_talk: dependency: "direct main" description: name: kakao_flutter_sdk_talk - sha256: e4aea82d5ac167c57dc2f6ea2e75ae5712d1ae29dadde1343df2c007591b6b53 + sha256: d13ef12ba6ec6e1a7d510834eebfbf15c0c902807873d404d7b1f05f48f9c253 url: "https://pub.dev" source: hosted - version: "1.9.2" + version: "1.9.6" kakao_flutter_sdk_template: dependency: transitive description: name: kakao_flutter_sdk_template - sha256: "7d38a7fe8984649f83e81831868aba0b85d058cd7c0568814f8e4dcb8dba4000" + sha256: "29738faf73a35ab0f8c2bd2ba7b15e46b22fafbf9cf9c7147d3e3d0747211dda" url: "https://pub.dev" source: hosted - version: "1.9.2" + version: "1.9.6" kakao_flutter_sdk_user: dependency: "direct main" description: name: kakao_flutter_sdk_user - sha256: "9d3bd35d5b31cf01d45c7d114ca0c589d5098d8e6efce6f13d574ea692ba6a62" + sha256: f3692feefad530bcfcdd1b8cf685b0c2c3da4a6d28a7df7f57529e57b7040f1b url: "https://pub.dev" source: hosted - version: "1.9.2" + version: "1.9.6" leak_tracker: dependency: transitive description: @@ -1009,13 +1009,13 @@ packages: source: hosted version: "3.0.1" shared_preferences: - dependency: transitive + dependency: "direct main" description: name: shared_preferences - sha256: d3bbe5553a986e83980916ded2f0b435ef2e1893dfaa29d5a7a790d0eca12180 + sha256: "746e5369a43170c25816cc472ee016d3a66bc13fcf430c0bc41ad7b4b2922051" url: "https://pub.dev" source: hosted - version: "2.2.3" + version: "2.3.2" shared_preferences_android: dependency: transitive description: @@ -1028,10 +1028,10 @@ packages: dependency: transitive description: name: shared_preferences_foundation - sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c" + sha256: "07e050c7cd39bad516f8d64c455f04508d09df104be326d8c02551590a0d513d" url: "https://pub.dev" source: hosted - version: "2.3.5" + version: "2.5.3" shared_preferences_linux: dependency: transitive description: @@ -1052,10 +1052,10 @@ packages: dependency: transitive description: name: shared_preferences_web - sha256: d762709c2bbe80626ecc819143013cc820fa49ca5e363620ee20a8b15a3e3daf + sha256: d2ca4132d3946fec2184261726b355836a82c33d7d5b67af32692aff18a4684e url: "https://pub.dev" source: hosted - version: "2.2.1" + version: "2.4.2" shared_preferences_windows: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e12c17d..e77a5e8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -61,6 +61,7 @@ dependencies: path: ^1.9.0 mime: ^1.0.6 http_parser: ^4.0.2 + shared_preferences: ^2.3.2 dev_dependencies: flutter_lints: ^4.0.0