From c0ad2d6b91cac2c9b63f4e10ffa8a1b7acb5a23e Mon Sep 17 00:00:00 2001 From: rajshinde046 Date: Thu, 2 May 2024 16:56:33 +0530 Subject: [PATCH] bloc --- .vscode/settings.json | 3 +- lib/data/network/network_api_services.dart | 2 +- lib/main.dart | 15 +- lib/resources/routes/routes.dart | 2 +- lib/view/login/LoginScreen.dart | 695 +++++++++++--------- lib/view/login/VerifyOtp.dart | 2 +- lib/view_model/LoginPage/Loginbloc.dart | 24 + lib/view_model/LoginPage/Loginobserver.dart | 14 + lib/view_model/SendOtp/sendOtpObserver.dart | 24 + lib/view_model/SendOtp/sendOtpbloc.dart | 33 + pubspec.lock | 24 + pubspec.yaml | 2 + 12 files changed, 513 insertions(+), 327 deletions(-) create mode 100644 lib/view_model/LoginPage/Loginbloc.dart create mode 100644 lib/view_model/LoginPage/Loginobserver.dart create mode 100644 lib/view_model/SendOtp/sendOtpObserver.dart create mode 100644 lib/view_model/SendOtp/sendOtpbloc.dart diff --git a/.vscode/settings.json b/.vscode/settings.json index c5f3f6b..2a96dec 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "java.configuration.updateBuildConfiguration": "interactive" + "java.configuration.updateBuildConfiguration": "interactive", + "dart.flutterSdkPath": "D:\\pooja\\fluttersdk\\flutter_3.16.9\\flutter" } \ No newline at end of file diff --git a/lib/data/network/network_api_services.dart b/lib/data/network/network_api_services.dart index 297b210..a669ce5 100644 --- a/lib/data/network/network_api_services.dart +++ b/lib/data/network/network_api_services.dart @@ -7,7 +7,7 @@ import 'package:traderscircuit/Utils/utils.dart'; import '../../Utils/base_manager.dart'; import 'base_api_services.dart'; -class NetworkApiServices extends BaseApiServices { +class NetworkApiServices { Dio dio = Dio(); String basicAuth = 'Basic ' + base64.encode( diff --git a/lib/main.dart b/lib/main.dart index 9624b71..fd04b83 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -13,6 +14,9 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:traderscircuit/resources/routes/routes.dart'; import 'package:onesignal_flutter/onesignal_flutter.dart'; +import 'view_model/LoginPage/Loginbloc.dart'; +import 'view_model/SendOtp/sendOtpbloc.dart'; + Future main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -39,7 +43,16 @@ Future main() async { ); SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, - ]).then((value) => runApp(const MyApp())); + ]).then((value) => runApp(MultiBlocProvider( + providers: [ + BlocProvider( + create: (context) => CounterBloc(), + ), + BlocProvider( + create: (context) => SendOtpBloc(), + ), + // Add more BlocProviders for other Blocs here if needed + ],child: const MyApp()))); } class MyApp extends StatefulWidget { diff --git a/lib/resources/routes/routes.dart b/lib/resources/routes/routes.dart index 485fc74..283d539 100644 --- a/lib/resources/routes/routes.dart +++ b/lib/resources/routes/routes.dart @@ -86,7 +86,7 @@ class AppRoutes { ), GetPage( name: RouteName.verifyotp, - page: () => const VerifyOTP(), + page: () => VerifyOTP(), ), //secureaccess diff --git a/lib/view/login/LoginScreen.dart b/lib/view/login/LoginScreen.dart index e0cfb95..c61bad2 100644 --- a/lib/view/login/LoginScreen.dart +++ b/lib/view/login/LoginScreen.dart @@ -2,6 +2,7 @@ import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:glassmorphism/glassmorphism.dart'; @@ -11,9 +12,15 @@ import 'package:traderscircuit/Utils/base_manager.dart'; import 'package:traderscircuit/Utils/text.dart'; import 'package:traderscircuit/Utils/utils.dart'; import 'package:traderscircuit/resources/routes/route_name.dart'; +import 'package:traderscircuit/view/login/VerifyOtp.dart'; import 'package:traderscircuit/view/onBoarding/splashScreen1.dart'; import 'package:traderscircuit/view_model/Login/send_otp_api.dart'; import 'package:traderscircuit/Utils/Dialogs.dart'; +import 'package:traderscircuit/view_model/LoginPage/Loginbloc.dart'; + +import '../../view_model/LoginPage/Loginobserver.dart'; +import '../../view_model/SendOtp/sendOtpObserver.dart'; +import '../../view_model/SendOtp/sendOtpbloc.dart'; class LoginScreen extends StatefulWidget { const LoginScreen({super.key}); @@ -33,6 +40,9 @@ class _LoginScreenState extends State { @override Widget build(BuildContext context) { + // final CounterBloc counterbloc = BlocProvider.of(context); + //final sendOtpBloc = context.read(); + return WillPopScope( onWillPop: () async { _onBackButtonPressed(context); @@ -41,343 +51,383 @@ class _LoginScreenState extends State { child: Scaffold( backgroundColor: Colors.black, extendBody: true, - body: Stack( - children: [ - const CommonBlurLeft(), - const CommonBlurRight(), - Stack( - children: [ - Padding( - padding: - const EdgeInsets.symmetric(horizontal: 16, vertical: 16), - child: Form( - key: _sendotpform, - child: ListView( - physics: const BouncingScrollPhysics(), - // mainAxisAlignment: MainAxisAlignment.start, - // crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: 20.h, - ), - const Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "Traders Circuit", - style: TextStyle( - fontFamily: 'hiragino', - color: Colors.white, - fontSize: 25, - fontWeight: FontWeight.w600), - ), - ], - ), - SizedBox( - height: 42.h, - ), - const Text( - "Lets get started ", - style: TextStyle( - fontFamily: 'hiragino', - color: Colors.white, - fontSize: 24, - fontWeight: FontWeight.w700), - ), - SizedBox( - height: 10.h, - ), - text18W800("Enter your mobile number to get otp"), - SizedBox( - height: 35.h, - ), - Row( - children: [ - Expanded( - child: GlassmorphicContainer( - width: 60, - height: 50, - borderRadius: 8, - blur: 10, - alignment: Alignment.center, - border: 0.8, - linearGradient: LinearGradient( + body: BlocProvider( + create: (context) => SendOtpBloc(), + child: Stack( + children: [ + const CommonBlurLeft(), + const CommonBlurRight(), + Stack( + children: [ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16, vertical: 16), + child: Form( + key: _sendotpform, + child: ListView( + physics: const BouncingScrollPhysics(), + // mainAxisAlignment: MainAxisAlignment.start, + // crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: 20.h, + ), + const Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "Traders Circuit", + style: TextStyle( + fontFamily: 'hiragino', + color: Colors.white, + fontSize: 25, + fontWeight: FontWeight.w600), + ), + ], + ), + SizedBox( + height: 42.h, + ), + //bloc implementation + /* GestureDetector( + onTap: () { + counterbloc.add(NumberIncreaseEvent()); + }, + child: SizedBox( + height: 80.h, + child: Text( + "click me", + style: TextStyle( + fontFamily: 'hiragino', + color: Colors.white, + fontSize: 24, + fontWeight: FontWeight.w700), + ), + ), + ), + if (state is UpdateState) + Text( + "${state.counter}", + style: TextStyle( + fontFamily: 'hiragino', + color: Colors.white, + fontSize: 24, + fontWeight: FontWeight.w700), + ), + */ + const Text( + "Lets get started ", + style: TextStyle( + fontFamily: 'hiragino', + color: Colors.white, + fontSize: 24, + fontWeight: FontWeight.w700), + ), + SizedBox( + height: 10.h, + ), + text18W800("Enter your mobile number to get otp"), + SizedBox( + height: 35.h, + ), + Row( + children: [ + Expanded( + child: GlassmorphicContainer( + width: 60, + height: 50, + borderRadius: 8, + blur: 10, + alignment: Alignment.center, + border: 0.8, + linearGradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + Colors.white.withOpacity(0.1), + const Color(0xFFFFFFFF) + .withOpacity(0.05), + ], + stops: const [ + 0.1, + 1, + ]), + borderGradient: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [ - Colors.white.withOpacity(0.1), - const Color(0xFFFFFFFF).withOpacity(0.05), + const Color(0xff9A0000).withOpacity(0.5), + const Color(0xFFffffff).withOpacity(0.5), ], - stops: const [ - 0.1, - 1, - ]), - borderGradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [ - const Color(0xff9A0000).withOpacity(0.5), - const Color(0xFFffffff).withOpacity(0.5), - ], - ), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - // SvgPicture.asset("assets/images/svg/india.svg"), - Image.asset( - "assets/images/png/india.png", - height: 25.h, - width: 25.h, - ), - const SizedBox( - width: 2, - ), - const Text( - "+91", - style: TextStyle( - fontFamily: 'hiragino', - fontSize: 15, - color: Colors.white, + ), + child: Row( + crossAxisAlignment: + CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + // SvgPicture.asset("assets/images/svg/india.svg"), + Image.asset( + "assets/images/png/india.png", + height: 25.h, + width: 25.h, ), - ) - ], + const SizedBox( + width: 2, + ), + const Text( + "+91", + style: TextStyle( + fontFamily: 'hiragino', + fontSize: 15, + color: Colors.white, + ), + ) + ], + ), ), ), - ), - const SizedBox( - width: 10, - ), - SizedBox( - width: 285.w, - child: CustomTextFormField( - texttype: TextInputType.phone, - textEditingController: phonecontroller, - // validator: (value) { - // if (value.isEmpty) { - // return 'Enter your phone number'; - // } else if (!RegExp(r'(^(?:[+0]9)?[0-9]{10}$)') - // .hasMatch(value)) { - // return 'Enter a valid phone number'; - // } else if (!isValidPhoneNumber(value)) { - // return 'Phone number cannot contain 10 zeros'; - // } - // return null; - // }, - inputFormatters: [ - LengthLimitingTextInputFormatter(10), - FilteringTextInputFormatter.allow( - RegExp('[0-9]')), + const SizedBox( + width: 10, + ), + SizedBox( + width: 285.w, + child: CustomTextFormField( + texttype: TextInputType.phone, + textEditingController: phonecontroller, + // validator: (value) { + // if (value.isEmpty) { + // return 'Enter your phone number'; + // } else if (!RegExp(r'(^(?:[+0]9)?[0-9]{10}$)') + // .hasMatch(value)) { + // return 'Enter a valid phone number'; + // } else if (!isValidPhoneNumber(value)) { + // return 'Phone number cannot contain 10 zeros'; + // } + // return null; + // }, + inputFormatters: [ + LengthLimitingTextInputFormatter(10), + FilteringTextInputFormatter.allow( + RegExp('[0-9]')), + ], + ), + ) + ], + ), + const SizedBox( + height: 10, + ), + text14W300( + "We’ll send six digit code to the registered number. Standard data rates may apply"), + SizedBox( + height: 65.h, + ), + + BlocConsumer( + listener: (context, state) { + if (state == SendOtpState.success) { + WidgetsBinding.instance + ?.addPostFrameCallback((_) { + Get.toNamed(RouteName.verifyotp, arguments: { + "phonenumber": phonecontroller.text, + }); + }); + } else if (state == SendOtpState.failure) { + Utils.showToast("Oops something went wrong"); + } + }, builder: (context, state) { + print(state); + if (state == SendOtpState.loading) { + return Center( + child: Container( + height: 40, + width: 40, + child: CircularProgressIndicator())); + } + return CommonBtn( + text: "Login/Signup", + onTap: () async { + final isValid = + _sendotpform.currentState?.validate(); + if (isValid!) { + FocusManager.instance.primaryFocus + ?.unfocus(); + if (isValid != null && isValid) { + Map myLoginData = { + "mobile_number": phonecontroller.text, + }; + context + .read() + .add(SendOtp(myLoginData)); + } else { + ScaffoldMessenger.of(context) + .showSnackBar( + SnackBar( + content: Text( + 'Please enter valid phone number'), + ), + ); + } + } + }); + }), + + SizedBox( + height: 10.h, + ), + text14W300( + "By continuing, you agree to our Terms & Conditions"), + SizedBox( + height: 45.h, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + height: 0.2.h, + width: 108.w, + color: Colors.white, + ), + SizedBox( + width: 22.w, + ), + text18W600("OR"), + SizedBox( + width: 22.w, + ), + Container( + height: 0.2.h, + width: 108.w, + color: Colors.white, + ), + ], + ), + SizedBox( + height: 40.h, + ), + GlassmorphicContainer( + width: double.infinity, + height: 55.h, + borderRadius: 8, + linearGradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + const Color(0xFFffffff).withOpacity(0.1), + const Color(0xFFFFFFFF).withOpacity(0.05), + ], + stops: const [ + 0.1, + 1, + ]), + border: 0.3, + blur: 10, + borderGradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + const Color(0xFFAF2E89).withOpacity(0.2), + const Color(0xFFA23E31).withOpacity(0.2), + const Color(0xFF0000).withOpacity(0.2), + ], + stops: const [ + 0.3, + 0.6, + 1, + ]), + child: Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset( + "assets/images/png/apple.png", + height: 30.h, + width: 30.w, + ), + SizedBox( + width: 7.h, + ), + text16W400("Continue with apple"), ], ), - ) - ], - ), - const SizedBox( - height: 10, - ), - text14W300( - "We’ll send six digit code to the registered number. Standard data rates may apply"), - SizedBox( - height: 65.h, - ), - CommonBtn( - text: "Login/Signup", - onTap: () async { - final isValid = - _sendotpform.currentState?.validate(); - if (isValid!) { - utils.loader(); - FocusManager.instance.primaryFocus?.unfocus(); - - Map myLoginData = { - "mobile_number": phonecontroller.text, - }; - - var resp = - await SendOtpAPI(myLoginData).sendOtpApi(); - print(resp.status); - print('Api msg : ${resp.message}'); - - if (resp.status == ResponseStatus.SUCCESS) { - Get.back(); - print("api response is ${resp.data}"); - Utils.showToast("OTP sent successfully"); - - Map res = resp.data; - print(res); - - Get.toNamed(RouteName.verifyotp, arguments: { - "phonenumber": phonecontroller.text - }); - } else { - Get.back(); - Utils.showToast(resp.message); - print('Api msg : ${resp.message}'); - } - } else { - Get.snackbar( - "Error", "Please Enter Login Credentials", - margin: EdgeInsets.all(8), - snackStyle: SnackStyle.FLOATING, - snackPosition: SnackPosition.BOTTOM); - } - }), - SizedBox( - height: 10.h, - ), - text14W300( - "By continuing, you agree to our Terms & Conditions"), - SizedBox( - height: 45.h, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - height: 0.2.h, - width: 108.w, - color: Colors.white, - ), - SizedBox( - width: 22.w, - ), - text18W600("OR"), - SizedBox( - width: 22.w, - ), - Container( - height: 0.2.h, - width: 108.w, - color: Colors.white, - ), - ], - ), - SizedBox( - height: 40.h, - ), - GlassmorphicContainer( - width: double.infinity, - height: 55.h, - borderRadius: 8, - linearGradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [ - const Color(0xFFffffff).withOpacity(0.1), - const Color(0xFFFFFFFF).withOpacity(0.05), - ], - stops: const [ - 0.1, - 1, - ]), - border: 0.3, - blur: 10, - borderGradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [ - const Color(0xFFAF2E89).withOpacity(0.2), - const Color(0xFFA23E31).withOpacity(0.2), - const Color(0xFF0000).withOpacity(0.2), - ], - stops: const [ - 0.3, - 0.6, - 1, - ]), - child: Center( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Image.asset( - "assets/images/png/apple.png", - height: 30.h, - width: 30.w, - ), - SizedBox( - width: 7.h, - ), - text16W400("Continue with apple"), - ], ), ), - ), - SizedBox( - height: 15.h, - ), - GlassmorphicContainer( - width: double.infinity, - height: 55.h, - borderRadius: 8, - linearGradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [ - const Color(0xFFffffff).withOpacity(0.1), - const Color(0xFFFFFFFF).withOpacity(0.05), - ], - stops: const [ - 0.1, - 1, - ]), - border: 0.5, - blur: 10, - borderGradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [ - const Color(0xFFAF2E89).withOpacity(0.2), - const Color(0xFFA23E31).withOpacity(0.2), - const Color(0xFF0000).withOpacity(0.2), - ], - stops: const [ - 0.3, - 0.6, - 1, - ]), - child: Center( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Image.asset( - "assets/images/png/google.png", - height: 30.h, - width: 30.w, - ), - SizedBox( - width: 7.h, - ), - text16W400( - "Continue with google", - ), - ], - ), + SizedBox( + height: 15.h, ), - ), - SizedBox( - height: 45.h, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - InkWell( - onTap: () { - Get.toNamed(RouteName.mainscreen); - }, - child: text16W700( - "Continue as guest", + GlassmorphicContainer( + width: double.infinity, + height: 55.h, + borderRadius: 8, + linearGradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + const Color(0xFFffffff).withOpacity(0.1), + const Color(0xFFFFFFFF).withOpacity(0.05), + ], + stops: const [ + 0.1, + 1, + ]), + border: 0.5, + blur: 10, + borderGradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + const Color(0xFFAF2E89).withOpacity(0.2), + const Color(0xFFA23E31).withOpacity(0.2), + const Color(0xFF0000).withOpacity(0.2), + ], + stops: const [ + 0.3, + 0.6, + 1, + ]), + child: Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset( + "assets/images/png/google.png", + height: 30.h, + width: 30.w, + ), + SizedBox( + width: 7.h, + ), + text16W400( + "Continue with google", + ), + ], ), ), - ], - ) - ], + ), + SizedBox( + height: 45.h, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + InkWell( + onTap: () { + Get.toNamed(RouteName.mainscreen); + }, + child: text16W700( + "Continue as guest", + ), + ), + ], + ) + ], + ), ), ), - ), - ], - ), - ], + ], + ), + ], + ), ), ), ); @@ -419,4 +469,5 @@ class _LoginScreenState extends State { ); }); return exitApp ?? false; - }} + } +} diff --git a/lib/view/login/VerifyOtp.dart b/lib/view/login/VerifyOtp.dart index 6582545..88b1dcd 100644 --- a/lib/view/login/VerifyOtp.dart +++ b/lib/view/login/VerifyOtp.dart @@ -20,7 +20,7 @@ int? isKycUpdated; int? isSecuredAccess; class VerifyOTP extends StatefulWidget { - const VerifyOTP({super.key}); + VerifyOTP({super.key}); @override State createState() => _VerifyOTPState(); diff --git a/lib/view_model/LoginPage/Loginbloc.dart b/lib/view_model/LoginPage/Loginbloc.dart new file mode 100644 index 0000000..19cb21d --- /dev/null +++ b/lib/view_model/LoginPage/Loginbloc.dart @@ -0,0 +1,24 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; + +import 'Loginobserver.dart'; + +class CounterBloc extends Bloc { + int counter = 0; + + CounterBloc() : super(UpdateState(0)) { + on(onNumberIncrease); + on(onNumberDecrease); + } + + void onNumberIncrease( + NumberIncreaseEvent event, Emitter emit) async { + counter = counter + 1; + emit(UpdateState(counter)); + } + + void onNumberDecrease( + NumberDecreaseEvent event, Emitter emit) async { + counter = counter - 1; + emit(UpdateState(counter)); + } +} \ No newline at end of file diff --git a/lib/view_model/LoginPage/Loginobserver.dart b/lib/view_model/LoginPage/Loginobserver.dart new file mode 100644 index 0000000..1bcea4a --- /dev/null +++ b/lib/view_model/LoginPage/Loginobserver.dart @@ -0,0 +1,14 @@ +class CounterEvents {} + +class NumberIncreaseEvent extends CounterEvents {} + +class NumberDecreaseEvent extends CounterEvents {} + +class CounterStates {} + +class InitialState extends CounterStates {} + +class UpdateState extends CounterStates { + final int counter; + UpdateState(this.counter); +} \ No newline at end of file diff --git a/lib/view_model/SendOtp/sendOtpObserver.dart b/lib/view_model/SendOtp/sendOtpObserver.dart new file mode 100644 index 0000000..a0b7bc7 --- /dev/null +++ b/lib/view_model/SendOtp/sendOtpObserver.dart @@ -0,0 +1,24 @@ +import 'package:equatable/equatable.dart'; + +// Define events +abstract class SendOtpEvent { + const SendOtpEvent(); + + @override + List get props => []; +} + +class SendOtp extends SendOtpEvent { + final Map loginData; + SendOtp(this.loginData){ + + } + + @override + List get props => [loginData]; + +} + +// Define states +enum SendOtpState { initial, loading, success, failure } + diff --git a/lib/view_model/SendOtp/sendOtpbloc.dart b/lib/view_model/SendOtp/sendOtpbloc.dart new file mode 100644 index 0000000..0ba9db0 --- /dev/null +++ b/lib/view_model/SendOtp/sendOtpbloc.dart @@ -0,0 +1,33 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:get/get.dart'; + +import '../../Utils/base_manager.dart'; +import '../../resources/routes/route_name.dart'; +import '../Login/send_otp_api.dart'; +import 'sendOtpObserver.dart'; + +class SendOtpBloc extends Bloc { + SendOtpBloc() : super(SendOtpState.initial) { + on(mapEventToState); + } + Future mapEventToState( + SendOtp event, Emitter emit) async { + if (event is SendOtp) { + emit(SendOtpState.loading); + try { + final loginData = event.loginData; + var resp = await SendOtpAPI(loginData).sendOtpApi(); + + if (resp.status == ResponseStatus.SUCCESS) { + emit(SendOtpState.success); + } else { + emit(SendOtpState.failure); + } + } catch (e) { + emit(SendOtpState.failure); + } + } + } +} + + diff --git a/pubspec.lock b/pubspec.lock index 0a94cf1..cfbb997 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,6 +49,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.2" + bloc: + dependency: transitive + description: + name: bloc + sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e" + url: "https://pub.dev" + source: hosted + version: "8.1.4" boolean_selector: dependency: transitive description: @@ -217,6 +225,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.9" + equatable: + dependency: "direct main" + description: + name: equatable + sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 + url: "https://pub.dev" + source: hosted + version: "2.0.5" expansion_tile_group: dependency: "direct main" description: @@ -318,6 +334,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_bloc: + dependency: "direct main" + description: + name: flutter_bloc + sha256: f0ecf6e6eb955193ca60af2d5ca39565a86b8a142452c5b24d96fb477428f4d2 + url: "https://pub.dev" + source: hosted + version: "8.1.5" flutter_branch_sdk: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index cdbbd7d..bbf3bac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -48,6 +48,8 @@ dependencies: audio_video_progress_bar: ^2.0.2 syncfusion_flutter_pdfviewer: flutter_html: ^3.0.0-beta.2 + flutter_bloc: ^8.1.5 + equatable: ^2.0.5 dev_dependencies: flutter_test: