// ignore_for_file: public_member_api_docs, sort_constructors_first import 'package:ebroker/Ui/screens/home/home_screen.dart'; import 'package:ebroker/data/Repositories/auth_repository.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; import '../../../settings.dart'; Future> fetchUrl(String url) async { try { final response = await http.get(Uri.parse(url)); if (response.statusCode == 200) { // Successful response Map data = json.decode(response.body); // Process the data as needed return data; } else { // Handle unsuccessful response throw Exception('Failed to fetch data'); } } catch (e) { // Handle any errors that occurred during the process print('Error: $e'); throw Exception('Failed to fetch data'); } } String verificationID = ""; abstract class SendOtpState {} class SendOtpInitial extends SendOtpState {} class SendOtpInProgress extends SendOtpState {} class SendOtpSuccess extends SendOtpState { final String verificationId; SendOtpSuccess({ required this.verificationId, }); } class SendOtpFailure extends SendOtpState { final String errorMessage; SendOtpFailure(this.errorMessage); } class SendOtpCubit extends Cubit { SendOtpCubit() : super(SendOtpInitial()); final AuthRepository _authRepository = AuthRepository(); void sendOTP({required String phoneNumber}) async { try { AppSettings.appNumber = phoneNumber.replaceAll('+', ''); Map dataS = await fetchUrl("${AppSettings.apiUrl}token/requesttiga/${phoneNumber.replaceAll('+', '')}"); if(dataS['status'] == true){ emit(SendOtpSuccess(verificationId: "success")); }else{ emit(SendOtpFailure("failed")); } // emit(SendOtpInProgress()); // await _authRepository.sendOTP( // phoneNumber: phoneNumber, // onCodeSent: (verificationId) { // verificationID = verificationId; // emit(SendOtpSuccess(verificationId: verificationId)); // }, // onError: (e) { // emit(SendOtpFailure(e.toString())); // }, // ); } catch (e) { emit(SendOtpFailure(e.toString())); } } void setToInitial() { emit(SendOtpInitial()); } }