-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add buttonsheet to detail product screan for show comments -> have a …
…bug for height bottonsheet
- Loading branch information
1 parent
125cdbf
commit 11a5bc4
Showing
8 changed files
with
268 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:apple_shop/bloc/comments/comment_event.dart'; | ||
import 'package:apple_shop/bloc/comments/comment_state.dart'; | ||
import 'package:apple_shop/data/repository/comments_reository.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class CommentBloc extends Bloc<CommentEvent, CommentState> { | ||
final ICommentsRepository _repository; | ||
|
||
CommentBloc(this._repository) : super(InitialCommentState()) { | ||
on<GetCommntsEvent>((event, emit) async { | ||
emit(LoadingCommentsState()); | ||
var response = await _repository.getComments(event.productId); | ||
|
||
emit(ResponseCommentState(response: response)); | ||
}); | ||
} | ||
} |
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,9 @@ | ||
abstract class CommentEvent {} | ||
|
||
class GetCommntsEvent extends CommentEvent { | ||
String productId; | ||
|
||
GetCommntsEvent({ | ||
required this.productId, | ||
}); | ||
} |
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,16 @@ | ||
import 'package:apple_shop/data/models/comments_models.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
|
||
abstract class CommentState {} | ||
|
||
class InitialCommentState extends CommentState {} | ||
|
||
class LoadingCommentsState extends CommentState {} | ||
|
||
class ResponseCommentState extends CommentState { | ||
Either<String, List<Comments>> response; | ||
|
||
ResponseCommentState({ | ||
required this.response, | ||
}); | ||
} |
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,41 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:apple_shop/data/models/comments_models.dart'; | ||
import 'package:apple_shop/di/service_locator.dart'; | ||
import 'package:apple_shop/util/api_exception.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
abstract class ICommentDataSource { | ||
Future<List<Comments>> getComments(String productId); | ||
} | ||
|
||
class CommentRemoteDataSource extends ICommentDataSource { | ||
final Dio _dio = locator.get(); | ||
@override | ||
Future<List<Comments>> getComments(String productId) async { | ||
try { | ||
Map<String, String> qparam = {"filter": 'product_id="$productId"'}; | ||
|
||
var response = await _dio.get( | ||
"collections/comment/records", | ||
queryParameters: qparam, | ||
); | ||
|
||
return response.data["items"].map((jsonMapObject) { | ||
return Comments.fromJson(jsonMapObject); | ||
}).toList(); | ||
|
||
|
||
} on DioException catch (ex) { | ||
throw ApiExceptiopn( | ||
code: ex.response!.statusCode!, | ||
messgae: ex.response!.data["message"], | ||
); | ||
} catch (ex) { | ||
throw ApiExceptiopn( | ||
code: 0, | ||
messgae: "خطا محتوای متنی ندارد", | ||
); | ||
} | ||
} | ||
} |
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,22 @@ | ||
class Comments { | ||
String id; | ||
String product_id; | ||
String text; | ||
String user_id; | ||
|
||
Comments({ | ||
required this.id, | ||
required this.product_id, | ||
required this.text, | ||
required this.user_id, | ||
}); | ||
|
||
factory Comments.fromJson(Map<String, dynamic> jsonMapObject) { | ||
return Comments( | ||
id: jsonMapObject["id"], | ||
product_id: jsonMapObject["product_id"], | ||
text: jsonMapObject["text"], | ||
user_id: jsonMapObject["user_id"], | ||
); | ||
} | ||
} |
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,22 @@ | ||
import 'package:apple_shop/data/datasource/comment_data_source.dart'; | ||
import 'package:apple_shop/data/models/comments_models.dart'; | ||
import 'package:apple_shop/di/service_locator.dart'; | ||
import 'package:apple_shop/util/api_exception.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
|
||
abstract class ICommentsRepository { | ||
Future<Either<String, List<Comments>>> getComments(String productId); | ||
} | ||
|
||
class CommenstRepository extends ICommentsRepository { | ||
ICommentDataSource _dataSource = locator.get(); | ||
@override | ||
Future<Either<String, List<Comments>>> getComments(String productId) async { | ||
try { | ||
var response = await _dataSource.getComments(productId); | ||
return Right(response); | ||
} on ApiExceptiopn catch (ex) { | ||
return Left(ex.messgae); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.