import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:muaawana/services/rating_services.dart'; import '../config/style.dart'; import '../utils/connection.dart'; import '../views/client_view/profile/profile_screen.dart'; class RatingDialogBoxProvider with ChangeNotifier { bool loader = false; bool checkbox1 = false; bool checkbox2 = false; bool checkbox3 = false; RatingServices get service => GetIt.I(); TextEditingController descriptionController = TextEditingController(); int rating = 0; publishRating( bool isProduct, int id, int? technicianId, BuildContext context) async { const vide = ''; const checkBoxOneString = '-Time-'; const checkBoxTwoString = '-Price-'; const checkBoxThreeString = '-Technicien-'; String reason = '${checkbox1 ? checkBoxOneString : vide}${checkbox2 ? checkBoxTwoString : vide}${checkbox3 ? checkBoxThreeString : vide}'; if (isProduct) { if (await Connection.checkConnection()) { //print('heerrrrreeee'); loader = true; notifyListeners(); try { final authResult = await service.publishProductRating( descriptionController.text, id, rating, reason); if ((authResult.statusCode == 200 || authResult.statusCode == 201)) { Navigator.push( context, MaterialPageRoute( builder: (context) => const ProfileScreenClient())); //print('Done Rating'); loader = false; notifyListeners(); // ignore: use_build_context_synchronously } else if (authResult.statusCode == 302) { updateProductServiceRating(isProduct, id); } else { //print('error 1'); loader = false; notifyListeners(); } } catch (e, stackTrace) { //print(stackTrace); //print('error 2'); loader = false; notifyListeners(); } } else { //print('error 3'); loader = false; notifyListeners(); } } else { //print('heerrrrreeee'); if (await Connection.checkConnection()) { loader = true; notifyListeners(); try { final authResult = await service.publishServiceRating( descriptionController.text, id, rating, reason, technicianId); //print("publish rating status code : ${authResult.statusCode}"); if (authResult.statusCode == 200 || authResult.statusCode == 201) { //print('Done Rating'); loader = false; notifyListeners(); // ignore: use_build_context_synchronously } else { loader = false; //print('error 11'); notifyListeners(); } } catch (e, stackTrace) { //print('error 12'); loader = false; notifyListeners(); } } else { //print('error 13'); loader = false; notifyListeners(); } } } getAllRating(bool isProduct, int size, int page) async { if (isProduct) { if (await Connection.checkConnection()) { //print('heerrrrreeee'); loader = true; notifyListeners(); try { final authResult = await service.getAllMyProductRating(size, page); if ((authResult.statusCode == 200 || authResult.statusCode == 201) // && // authResult.data != null ) { //print('Done Rating'); loader = false; notifyListeners(); // ignore: use_build_context_synchronously } else { //print('error 1'); loader = false; notifyListeners(); } } catch (e, stackTrace) { //print(stackTrace); //print('error 2'); loader = false; notifyListeners(); } } else { //print('error 3'); loader = false; notifyListeners(); } } else { //print('heerrrrreeee'); if (await Connection.checkConnection()) { loader = true; notifyListeners(); try { final authResult = await service.getAllMyServiceRating(size, page); if ((authResult.statusCode == 200 || authResult.statusCode == 201) && authResult.data != null) { //print('Done Rating'); loader = false; notifyListeners(); // ignore: use_build_context_synchronously } else { loader = false; //print('error 11'); notifyListeners(); } } catch (e, stackTrace) { //print('error 12'); loader = false; notifyListeners(); } } else { //print('error 13'); loader = false; notifyListeners(); } } } getRatingById(bool isProduct, int id) async { if (isProduct) { if (await Connection.checkConnection()) { //print('heerrrrreeee'); loader = true; notifyListeners(); try { final authResult = await service.getProductRatingById(id); if ((authResult.statusCode == 200 || authResult.statusCode == 201) // && // authResult.data != null ) { //print('Done Rating'); loader = false; notifyListeners(); // ignore: use_build_context_synchronously } else { //print('error 1'); loader = false; notifyListeners(); } } catch (e, stackTrace) { //print(stackTrace); //print('error 2'); loader = false; notifyListeners(); } } else { //print('error 3'); loader = false; notifyListeners(); } } else { //print('heerrrrreeee'); if (await Connection.checkConnection()) { loader = true; notifyListeners(); try { final authResult = await service.getProductRatingById(id); if ((authResult.statusCode == 200 || authResult.statusCode == 201) && authResult.data != null) { //print('Done Rating'); loader = false; notifyListeners(); // ignore: use_build_context_synchronously } else { loader = false; //print('error 11'); notifyListeners(); } } catch (e, stackTrace) { //print('error 12'); loader = false; notifyListeners(); } } else { //print('error 13'); loader = false; notifyListeners(); } } } updateProductServiceRating(bool isProduct, int id) async { const vide = ''; const checkBoxOneString = '-Time-'; const checkBoxTwoString = '-Price-'; const checkBoxThreeString = '-Technicien-'; String reason = '${checkbox1 ? checkBoxOneString : vide}${checkbox2 ? checkBoxTwoString : vide}${checkbox3 ? checkBoxThreeString : vide}'; if (isProduct) { if (await Connection.checkConnection()) { //print('heerrrrreeee'); loader = true; notifyListeners(); try { final authResult = await service.updateProductRating( descriptionController.text, id, rating, reason); if ((authResult.statusCode == 200 || authResult.statusCode == 201) // && // authResult.data != null ) { //print('Done Rating'); loader = false; notifyListeners(); // ignore: use_build_context_synchronously } else { //print('error 1'); loader = false; notifyListeners(); } } catch (e, stackTrace) { //print(stackTrace); //print('error 2'); loader = false; notifyListeners(); } } else { //print('error 3'); loader = false; notifyListeners(); } } else { //print('heerrrrreeee'); if (await Connection.checkConnection()) { loader = true; notifyListeners(); try { final authResult = await service.updateServiceRating( descriptionController.text, id, rating, reason); if ((authResult.statusCode == 200 || authResult.statusCode == 201) && authResult.data != null) { //print('Done Rating'); loader = false; notifyListeners(); // ignore: use_build_context_synchronously } else { loader = false; //print('error 11'); notifyListeners(); } } catch (e, stackTrace) { //print('error 12'); loader = false; notifyListeners(); } } else { //print('error 13'); loader = false; notifyListeners(); } } } _dispose() { descriptionController = TextEditingController(text: ''); } bool navigateToOtherScreen = false; void updateCheckbox1(bool newValue) { checkbox1 = newValue; notifyListeners(); } void updateCheckbox2(bool newValue) { checkbox2 = newValue; notifyListeners(); } void updateCheckbox3(bool newValue) { checkbox3 = newValue; notifyListeners(); } void updateDescription(String newValue) { descriptionController = TextEditingController(text: newValue); notifyListeners(); } void updateRating(int value) { rating = value; notifyListeners(); } Color getColor(Set states) { const Set interactiveStates = { MaterialState.selected, MaterialState.focused, MaterialState.pressed, }; if (states.any(interactiveStates.contains)) { return Colors.transparent; } return AppStyle.textCategGrey; } void onClose() { // do any necessary state updates checkbox1 = false; checkbox2 = false; checkbox3 = false; _dispose(); //print("AlertBox Closed"); //Navigator.of(context).pop(); } void onSend() { // do any necessary state updates //print("Data Sent"); // Navigator.push( // context, // MaterialPageRoute(builder: (context) => NextScreen()), // ); } }