-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d52321
commit 7fe11b6
Showing
11 changed files
with
141 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:tuti/constants/string.dart'; | ||
import 'package:tuti/features/tutis/models/goods.dart'; | ||
|
||
final goodsProvider = FutureProvider<List<Goods>>((ref) async { | ||
final dio = Dio(); | ||
final response = await dio.get('${StringConstants.baseUrl}/products'); | ||
|
||
if (response.statusCode == 200) { | ||
final List<dynamic> goods = response.data['data']; | ||
final goodsList = goods.map((e) => Goods.fromJson(e)).toList(); | ||
return goodsList; | ||
} else { | ||
throw Exception('Failed to load Goods'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
enum TokenState { | ||
present, | ||
absent, | ||
} | ||
|
||
final tokenProvider = StateProvider((ref) => TokenState.absent); | ||
final tokenProvider = StateProvider<String?>((ref) => ''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
class Goods { | ||
final String title; | ||
final String name; | ||
final double? regularPrice; | ||
final double? discountRate; | ||
final double discountedPrice; | ||
final String? discountPolicy; | ||
|
||
const Goods( | ||
{required this.title, | ||
{required this.name, | ||
required this.discountedPrice, | ||
this.discountRate, | ||
this.regularPrice}); | ||
this.regularPrice, | ||
this.discountPolicy}); | ||
|
||
factory Goods.fromJson(Map<String, dynamic> json) { | ||
return Goods( | ||
name: json['name'], | ||
regularPrice: json['price'], | ||
discountRate: json['discountValue'], | ||
discountedPrice: json['discountedPrice'], | ||
discountPolicy: json['discountPolicy']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters