-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π μν API μ μ©μ λ°λ₯Έ λ‘μ§ μμ #12
Conversation
final response = await dio.get('${StringConstants.baseUrl}/products'); | ||
|
||
if (response.statusCode == 200) { | ||
final List<dynamic> goods = response.data['data']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μν apiμ data keyμλ valueμ νμ μ΄ Listμ΄λ―λ‘ List μΌλ‘ νμ μ€μ νμ¬ λ³μμ ν λΉ.
if (response.statusCode == 200) { | ||
final List<dynamic> goods = response.data['data']; | ||
final goodsList = goods.map((e) => Goods.fromJson(e)).toList(); | ||
return goodsList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list μμ λ μνλ€μ Goods κ°μ²΄λ‘ 맀ννμ¬ Listμ μμλ‘ μΆκ°
absent, | ||
} | ||
|
||
final tokenProvider = StateProvider((ref) => TokenState.absent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TokenStateλ₯Ό μμλ‘ μ‘΄μ¬, μ‘΄μ¬νμ§ μμμΌλ‘ κ΄λ¦¬νλ €κ³ νμΌλ μ€μ ν ν°μ μ μ₯νλ κ²μ΄ μλλΌ μν λ°μ νΈλνΉμ΄ μ΄μ€μΌλ‘ λ°μν΄ μ€μ ν ν°μ μ μ₯ν΄ isEmpty λλ ν ν° κ°μΌλ‘ μνλ₯Ό κ΄λ¦¬νλ κ²μΌλ‘ λ³κ²½
final token = await CustomTokenManager.getToken(); | ||
print('λ‘κ·ΈμΈ μ μ μ₯λλ ν ν°: $token'); | ||
|
||
ref.read(tokenProvider.notifier).state = token; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμκ°μ μλ£μ login λ©μλμ μλ²μμ λ°μμ¨ ν ν°μ local storageμ μ μ₯νκΈ° λλ¬Έμ getToken λ©μλλ₯Ό ν΅ν΄ λΆλ¬μ¨ λ€μ
tokenProviderμ μνμ μ μ₯.
ref.read(tokenProvider.notifier).state = TokenState.present; | ||
final token = await CustomTokenManager.getToken(); | ||
|
||
ref.read(tokenProvider.notifier).state = token; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ νμκ°μ μ μ μ©ν λ‘μ§κ³Ό λμΌ.
regularPrice: json['price'], | ||
discountRate: json['discountValue'], | ||
discountedPrice: json['discountedPrice'], | ||
discountPolicy: json['discountPolicy']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μν APIμ κ°λ³ μν κ°μ²΄μ ꡬ쑰μ λ§κ² μμ .
Widget build(BuildContext context) { | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final AsyncValue<List<Goods>> goodsList = ref.watch(goodsProvider); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goodsProviderλ FutureProviderλ‘ λΉλκΈ° κ°(AsyncValue)μ μ²λ¦¬νλ―λ‘ μμ κ°μ΄ λ³μ μμ±.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λν μ΄λ₯Ό watchν΄ goodsProviderμ μνκ° λ³κ²½λ λλ§λ€(μν λ³κ²½) ν΄λΉ νμ΄μ§ rebuild.
children: [ | ||
RSizedBox(height: 35.w), | ||
RSizedBox(height: 35.w), | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ²μμ λ°μν λ‘μ§μ λ°λΌ μ¦, μ λ₯ μ κ°μ λ°λΌ λ°μνλ λ‘μ§ κ΅¬ν
} else if (name.length == 2) { | ||
String firstName = name.substring(0, 1); | ||
String maskName = firstName + "*"; | ||
return maskName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ μ μ μ΄λ¦μ΄ λ κΈμ μΌλμ κ²½μ°μ λν μ²λ¦¬λ μ μ©.
return const SizedBox(); | ||
} | ||
if (snapshot.connectionState == ConnectionState.done) { | ||
if (snapshot.hasData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
futureμ μν(connectionState)κ° waitingμΌ λμ doneμΌ λλ₯Ό λ°μνκΈ° μν΄ μμ .
Title
π μν API μ μ©μ λ°λ₯Έ λ‘μ§ μμ
What type of PR is this?
Description
Related Issue number and link
Mobile & Desktop Screenshots/Recordings
product-.api-.mp4
Checklist:
To Reviewers