From 4b6a33aac407ef94b3af0b0c9f5098075afecf07 Mon Sep 17 00:00:00 2001 From: bestonemitRam Date: Sat, 22 Mar 2025 18:54:15 +0530 Subject: [PATCH] product review --- .DS_Store | Bin 10244 -> 10244 bytes .dart_tool/package_config.json | 8 +- .dart_tool/package_config_subset | 4 + .flutter-plugins-dependencies | 2 +- lib/src/core/constant/api.dart | 5 + lib/src/logic/provider/order_provider.dart | 41 ++++- lib/src/logic/provider/profile_provider.dart | 19 +- lib/src/logic/repo/order_repo.dart | 19 +- lib/src/logic/services/orderSirvice.dart | 6 + lib/src/ui/cart/cartview_screen.dart | 6 +- .../ui/edit_profile/edit_profile_screen.dart | 5 +- lib/src/ui/login/signup_screen.dart | 3 +- lib/src/ui/myOrder/OrderDetailsScreen.dart | 43 +++-- lib/src/ui/product_review.dart | 164 ++++++++++++++++++ pubspec.lock | 8 + pubspec.yaml | 1 + 16 files changed, 295 insertions(+), 39 deletions(-) create mode 100644 lib/src/ui/product_review.dart diff --git a/.DS_Store b/.DS_Store index a30432637e9316e8dbda507233ab03de6045f44c..6dbf4dbea096e05e464bdbfaaaa2a3c13f1b890e 100644 GIT binary patch delta 364 zcmZn(XbG6$FKWxcz`)4BAi%&-!VnL{`9PSnF>x{bW_Au1j(U(Z7lR%{3PU185wen; zbi?4}{M-VdJkS8fC%Dw*=DWBg<>V&;A!t)HI>H`x1ADddm delta 135 zcmZn(XbG6$FKEfYz`)4BAi$85ZWx@LpIfl8a2or>2Eonj94s8NAXyd$J%)6KOokGe z3ZNJRLs&%c24YzD1I*{>d%{7yg$#^e)}W{Oy_SzC~ekuh$wk productReview( + BuildContext context, + dynamic data, + String productId, + ) async { + context.showLoader(show: true); + notifyListeners(); + + try { + var result = await _orderRepo.productReview(data, productId); + + return result.fold( + (error) + { + context.showLoader(show: false); + return false; + }, + (response) + { + context.showLoader(show: false); + return true; + }, + ); + } catch (e) + { + context.showLoader(show: false); + Fluttertoast.showToast( + msg: "Something went wrong", + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.BOTTOM, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 14.0, + ); + return false; + } + } + void _showOtpPopup(BuildContext context, String otp) { showDialog( context: context, diff --git a/lib/src/logic/provider/profile_provider.dart b/lib/src/logic/provider/profile_provider.dart index b6fce5e..5bf27c5 100644 --- a/lib/src/logic/provider/profile_provider.dart +++ b/lib/src/logic/provider/profile_provider.dart @@ -48,12 +48,19 @@ class ProfileProvider extends ChangeNotifier { Future updateProfile( BuildContext context, String firstName, String lastName) async { context.showLoader(show: true); - - var data = { - "firstName": firstName, - "lastName": lastName, - "img": _uploadedUrl - }; + var data; + if (_uploadedUrl.isEmpty) { + data = { + "firstName": firstName, + "lastName": lastName, + }; + } else { + data = { + "firstName": firstName, + "lastName": lastName, + "img": _uploadedUrl + }; + } try { var result = await _productRepo.updateProfile(data); diff --git a/lib/src/logic/repo/order_repo.dart b/lib/src/logic/repo/order_repo.dart index 5407880..88b08c4 100644 --- a/lib/src/logic/repo/order_repo.dart +++ b/lib/src/logic/repo/order_repo.dart @@ -25,12 +25,22 @@ class OrderRepo { return left(error); } } - + FutureResult productReview(data,id) async + { + try { + var response = await _orderService.productReview(data,id); - + String model = response.toString(); + return right(model); + } on DioException catch (e) + { + var error = CustomDioExceptions.handleError(e); + return left(error); + } + } - FutureResult getAssignedOtp(data) async { + FutureResult getAssignedOtp(data) async { try { var response = await _orderService.getAssignedOtp(data); @@ -56,7 +66,4 @@ class OrderRepo { return left(error); } } - - - } diff --git a/lib/src/logic/services/orderSirvice.dart b/lib/src/logic/services/orderSirvice.dart index de96db6..dcc8c63 100644 --- a/lib/src/logic/services/orderSirvice.dart +++ b/lib/src/logic/services/orderSirvice.dart @@ -14,6 +14,12 @@ class OrderService extends ApiService } + Future productReview(data,id) async { + var response = await api.post(APIURL.productReview+id+"/reviews", data: jsonEncode(data)); + + return response; + } + diff --git a/lib/src/ui/cart/cartview_screen.dart b/lib/src/ui/cart/cartview_screen.dart index 341d7f1..024ff28 100644 --- a/lib/src/ui/cart/cartview_screen.dart +++ b/lib/src/ui/cart/cartview_screen.dart @@ -760,7 +760,8 @@ class _MycartState extends State { color: Colors.white, ), ); - } else if (provider.allitem == null) { + } else if (provider.allitem == null) + { return Center(child: Text('🛒 Your Front Shop Cart is empty')); } else if (provider.allitem.items == null || provider.allitem.items!.isEmpty) { @@ -790,7 +791,8 @@ class _MycartState extends State { size: 15, ), onTap: () { - if (provider.couponDataModel.data!.isNotEmpty) { + if (provider.couponDataModel.data!.isNotEmpty) + { context.push(MyRoutes.COUPONSSCREEN, extra: provider.allitem.id); } else { diff --git a/lib/src/ui/edit_profile/edit_profile_screen.dart b/lib/src/ui/edit_profile/edit_profile_screen.dart index 2eeb850..a6c62bd 100644 --- a/lib/src/ui/edit_profile/edit_profile_screen.dart +++ b/lib/src/ui/edit_profile/edit_profile_screen.dart @@ -115,8 +115,7 @@ class _EditProfileScreenState extends State { ), Expanded( child: InkWell( - onTap: imageProvider.isImageLoading - ? () async { + onTap: () async { var status = await imageProvider.updateProfile( context, firstController.text, @@ -126,7 +125,7 @@ class _EditProfileScreenState extends State { Navigator.pop(context); } } - : null, + , child: Container( height: 50, decoration: BoxDecoration( diff --git a/lib/src/ui/login/signup_screen.dart b/lib/src/ui/login/signup_screen.dart index 35acd54..39efe42 100644 --- a/lib/src/ui/login/signup_screen.dart +++ b/lib/src/ui/login/signup_screen.dart @@ -103,7 +103,8 @@ class _SingnuScreenState extends State { ), ), ), - bottomNavigationBar: Container( + bottomNavigationBar: + Container( decoration: BoxDecoration( color: Colors.greenAccent.withOpacity(0.1), ), diff --git a/lib/src/ui/myOrder/OrderDetailsScreen.dart b/lib/src/ui/myOrder/OrderDetailsScreen.dart index 9f78b7d..aadee57 100644 --- a/lib/src/ui/myOrder/OrderDetailsScreen.dart +++ b/lib/src/ui/myOrder/OrderDetailsScreen.dart @@ -4,6 +4,7 @@ import 'package:gap/gap.dart'; import 'package:grocery_app/src/common_widget/network_image.dart'; import 'package:grocery_app/src/data/myOrder.dart'; import 'package:grocery_app/src/logic/provider/order_provider.dart'; +import 'package:grocery_app/src/ui/product_review.dart'; import 'package:grocery_app/utils/extensions/extensions.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -284,26 +285,34 @@ class _OrderDetailsScreenState extends State { ], ), ), + if (orderitem.orderItemStatus == "DELIVERED") - RichText( - text: TextSpan( - text: " ", - style: context.buttonTestStyle.copyWith( - color: context.appColor.blackColor, - ), - children: [ - TextSpan( - text: "Give Feedback", - style: context.buttonTestStyle.copyWith( - color: Colors.blue, - decoration: TextDecoration.underline, - ), - recognizer: TapGestureRecognizer() - ..onTap = () {}, - ), - ], + RichText( + text: TextSpan( + text: " ", + style: context.buttonTestStyle.copyWith( + color: context.appColor.blackColor, ), + children: [ + TextSpan( + text: "Give Feedback", + style: context.buttonTestStyle.copyWith( + color: Colors.blue, + decoration: TextDecoration.underline, + ), + recognizer: TapGestureRecognizer()..onTap = () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + RatingScreen(orderId: orderitem.productId), + ), + ); + }, + ), + ], ), + ), ], ), ), diff --git a/lib/src/ui/product_review.dart b/lib/src/ui/product_review.dart new file mode 100644 index 0000000..bcce1a2 --- /dev/null +++ b/lib/src/ui/product_review.dart @@ -0,0 +1,164 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_rating_bar/flutter_rating_bar.dart'; +import 'package:grocery_app/src/logic/provider/order_provider.dart'; +import 'package:grocery_app/utils/constants/color_constant.dart'; +import 'package:grocery_app/utils/extensions/uicontext.dart'; + +import 'package:image_picker/image_picker.dart'; +import 'dart:io'; + +import 'package:provider/provider.dart'; + +class RatingScreen extends StatefulWidget { + final String orderId; + const RatingScreen({Key? key, required this.orderId}) : super(key: key); + + @override + _RatingScreenState createState() => _RatingScreenState(); +} + +class _RatingScreenState extends State { + double _rating = 0.0; + final TextEditingController _titleController = TextEditingController(); + final TextEditingController _descriptionController = TextEditingController(); + List _selectedImages = []; + + Future _pickImage() async { + final pickedFile = + await ImagePicker().pickImage(source: ImageSource.gallery); + if (pickedFile != null) { + setState(() { + _selectedImages.add(File(pickedFile.path)); + }); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: + AppBar(backgroundColor: Colors.white, title: Text("Give a Rating")), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text("Rate this product:", + style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), + SizedBox(height: 10), + RatingBar.builder( + initialRating: 0, + minRating: 1, + direction: Axis.horizontal, + allowHalfRating: true, + itemCount: 5, + itemPadding: EdgeInsets.symmetric(horizontal: 4.0), + itemBuilder: (context, _) => + Icon(Icons.star, color: Colors.amber), + onRatingUpdate: (rating) { + setState(() { + _rating = rating; + }); + }, + ), + SizedBox(height: 20), + TextField( + controller: _titleController, + decoration: InputDecoration(labelText: "Title"), + ), + SizedBox(height: 10), + TextField( + controller: _descriptionController, + decoration: InputDecoration(labelText: "Description"), + maxLines: 3, + ), + SizedBox(height: 20), + Wrap( + spacing: 8, + children: _selectedImages + .map((file) => Image.file(file, width: 60, height: 60)) + .toList(), + ), + SizedBox(height: 10), + ElevatedButton( + onPressed: _pickImage, + child: Text("Upload Image"), + ), + Spacer(), + Consumer(builder: (context, provider, child) { + return Container( + decoration: BoxDecoration( + color: Colors.greenAccent.withOpacity(0.1), + ), + height: 100, + child: Padding( + padding: context.bodyAllPadding.copyWith(bottom: 20), + child: Center( + child: InkWell( + onTap: () async { + final ratingData = { + "rating": _rating, + "title": _titleController.text, + "description": _descriptionController.text, + "imageUrls": + _selectedImages.map((file) => file.path).toList(), + }; + var response = await provider.productReview( + context, ratingData, widget.orderId); + if (response) { + Navigator.pop(context); + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text("failed to Give feedback"), + ), + ); + } + + // if (_formKey.currentState?.validate() ?? false) { + // final success = await pageNotifier.sendOtp( + // phoneController.text, context); + + // if (success) { + // context.push(MyRoutes.OTPSCREEN); + // } else { + // ScaffoldMessenger.of(context).showSnackBar( + // SnackBar( + // content: + // Text("Failed to send OTP. Please try again."), + // ), + // ); + // } + // } else { + // ScaffoldMessenger.of(context).showSnackBar( + // SnackBar( + // content: + // Text("Enter a valid 10-digit phone number."), + // ), + // ); + // } + }, + child: Container( + height: 50, + width: MediaQuery.sizeOf(context).width, + decoration: BoxDecoration( + color: APPCOLOR.appGreen, + borderRadius: BorderRadius.circular(4)), + child: Center( + child: Text( + "Submit", + style: context.customMedium(Colors.white, 16), + ), + ), + ), + ), + ), + ), + ); + }) + ], + ), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 56cacbf..c1a7429 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -374,6 +374,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.22" + flutter_rating_bar: + dependency: "direct main" + description: + name: flutter_rating_bar + sha256: d2af03469eac832c591a1eba47c91ecc871fe5708e69967073c043b2d775ed93 + url: "https://pub.dev" + source: hosted + version: "4.0.1" flutter_rating_stars: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 0a2bdb0..d91888c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: skeletonizer: ^1.4.3 art_sweetalert: ^0.0.5 blur: + flutter_rating_bar: