bloc
This commit is contained in:
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"java.configuration.updateBuildConfiguration": "interactive"
|
"java.configuration.updateBuildConfiguration": "interactive",
|
||||||
|
"dart.flutterSdkPath": "D:\\pooja\\fluttersdk\\flutter_3.16.9\\flutter"
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ import 'package:traderscircuit/Utils/utils.dart';
|
|||||||
import '../../Utils/base_manager.dart';
|
import '../../Utils/base_manager.dart';
|
||||||
import 'base_api_services.dart';
|
import 'base_api_services.dart';
|
||||||
|
|
||||||
class NetworkApiServices extends BaseApiServices {
|
class NetworkApiServices {
|
||||||
Dio dio = Dio();
|
Dio dio = Dio();
|
||||||
String basicAuth = 'Basic ' +
|
String basicAuth = 'Basic ' +
|
||||||
base64.encode(
|
base64.encode(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
|||||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.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:traderscircuit/resources/routes/routes.dart';
|
||||||
import 'package:onesignal_flutter/onesignal_flutter.dart';
|
import 'package:onesignal_flutter/onesignal_flutter.dart';
|
||||||
|
|
||||||
|
import 'view_model/LoginPage/Loginbloc.dart';
|
||||||
|
import 'view_model/SendOtp/sendOtpbloc.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
@@ -39,7 +43,16 @@ Future<void> main() async {
|
|||||||
);
|
);
|
||||||
SystemChrome.setPreferredOrientations([
|
SystemChrome.setPreferredOrientations([
|
||||||
DeviceOrientation.portraitUp,
|
DeviceOrientation.portraitUp,
|
||||||
]).then((value) => runApp(const MyApp()));
|
]).then((value) => runApp(MultiBlocProvider(
|
||||||
|
providers: [
|
||||||
|
BlocProvider<CounterBloc>(
|
||||||
|
create: (context) => CounterBloc(),
|
||||||
|
),
|
||||||
|
BlocProvider<SendOtpBloc>(
|
||||||
|
create: (context) => SendOtpBloc(),
|
||||||
|
),
|
||||||
|
// Add more BlocProviders for other Blocs here if needed
|
||||||
|
],child: const MyApp())));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatefulWidget {
|
class MyApp extends StatefulWidget {
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class AppRoutes {
|
|||||||
),
|
),
|
||||||
GetPage(
|
GetPage(
|
||||||
name: RouteName.verifyotp,
|
name: RouteName.verifyotp,
|
||||||
page: () => const VerifyOTP(),
|
page: () => VerifyOTP(),
|
||||||
),
|
),
|
||||||
|
|
||||||
//secureaccess
|
//secureaccess
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'dart:ui';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:glassmorphism/glassmorphism.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/text.dart';
|
||||||
import 'package:traderscircuit/Utils/utils.dart';
|
import 'package:traderscircuit/Utils/utils.dart';
|
||||||
import 'package:traderscircuit/resources/routes/route_name.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/onBoarding/splashScreen1.dart';
|
||||||
import 'package:traderscircuit/view_model/Login/send_otp_api.dart';
|
import 'package:traderscircuit/view_model/Login/send_otp_api.dart';
|
||||||
import 'package:traderscircuit/Utils/Dialogs.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 {
|
class LoginScreen extends StatefulWidget {
|
||||||
const LoginScreen({super.key});
|
const LoginScreen({super.key});
|
||||||
@@ -33,6 +40,9 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
// final CounterBloc counterbloc = BlocProvider.of<CounterBloc>(context);
|
||||||
|
//final sendOtpBloc = context.read<SendOtpBloc>();
|
||||||
|
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
onWillPop: () async {
|
onWillPop: () async {
|
||||||
_onBackButtonPressed(context);
|
_onBackButtonPressed(context);
|
||||||
@@ -41,15 +51,17 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
backgroundColor: Colors.black,
|
backgroundColor: Colors.black,
|
||||||
extendBody: true,
|
extendBody: true,
|
||||||
body: Stack(
|
body: BlocProvider<SendOtpBloc>(
|
||||||
|
create: (context) => SendOtpBloc(),
|
||||||
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
const CommonBlurLeft(),
|
const CommonBlurLeft(),
|
||||||
const CommonBlurRight(),
|
const CommonBlurRight(),
|
||||||
Stack(
|
Stack(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding:
|
padding: const EdgeInsets.symmetric(
|
||||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
horizontal: 16, vertical: 16),
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _sendotpform,
|
key: _sendotpform,
|
||||||
child: ListView(
|
child: ListView(
|
||||||
@@ -76,6 +88,33 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: 42.h,
|
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(
|
const Text(
|
||||||
"Lets get started ",
|
"Lets get started ",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@@ -106,7 +145,8 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
end: Alignment.bottomRight,
|
end: Alignment.bottomRight,
|
||||||
colors: [
|
colors: [
|
||||||
Colors.white.withOpacity(0.1),
|
Colors.white.withOpacity(0.1),
|
||||||
const Color(0xFFFFFFFF).withOpacity(0.05),
|
const Color(0xFFFFFFFF)
|
||||||
|
.withOpacity(0.05),
|
||||||
],
|
],
|
||||||
stops: const [
|
stops: const [
|
||||||
0.1,
|
0.1,
|
||||||
@@ -121,7 +161,8 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
// SvgPicture.asset("assets/images/svg/india.svg"),
|
// SvgPicture.asset("assets/images/svg/india.svg"),
|
||||||
@@ -181,48 +222,56 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: 65.h,
|
height: 65.h,
|
||||||
),
|
),
|
||||||
CommonBtn(
|
|
||||||
|
BlocConsumer<SendOtpBloc, SendOtpState>(
|
||||||
|
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",
|
text: "Login/Signup",
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final isValid =
|
final isValid =
|
||||||
_sendotpform.currentState?.validate();
|
_sendotpform.currentState?.validate();
|
||||||
if (isValid!) {
|
if (isValid!) {
|
||||||
utils.loader();
|
FocusManager.instance.primaryFocus
|
||||||
FocusManager.instance.primaryFocus?.unfocus();
|
?.unfocus();
|
||||||
|
if (isValid != null && isValid) {
|
||||||
Map<String, String> myLoginData = {
|
Map<String, String> myLoginData = {
|
||||||
"mobile_number": phonecontroller.text,
|
"mobile_number": phonecontroller.text,
|
||||||
};
|
};
|
||||||
|
context
|
||||||
var resp =
|
.read<SendOtpBloc>()
|
||||||
await SendOtpAPI(myLoginData).sendOtpApi();
|
.add(SendOtp(myLoginData));
|
||||||
print(resp.status);
|
} else {
|
||||||
print('Api msg : ${resp.message}');
|
ScaffoldMessenger.of(context)
|
||||||
|
.showSnackBar(
|
||||||
if (resp.status == ResponseStatus.SUCCESS) {
|
SnackBar(
|
||||||
Get.back();
|
content: Text(
|
||||||
print("api response is ${resp.data}");
|
'Please enter valid phone number'),
|
||||||
Utils.showToast("OTP sent successfully");
|
),
|
||||||
|
);
|
||||||
Map<String, dynamic> 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(
|
SizedBox(
|
||||||
height: 10.h,
|
height: 10.h,
|
||||||
),
|
),
|
||||||
@@ -380,6 +429,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,4 +469,5 @@ class _LoginScreenState extends State<LoginScreen> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
return exitApp ?? false;
|
return exitApp ?? false;
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ int? isKycUpdated;
|
|||||||
int? isSecuredAccess;
|
int? isSecuredAccess;
|
||||||
|
|
||||||
class VerifyOTP extends StatefulWidget {
|
class VerifyOTP extends StatefulWidget {
|
||||||
const VerifyOTP({super.key});
|
VerifyOTP({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<VerifyOTP> createState() => _VerifyOTPState();
|
State<VerifyOTP> createState() => _VerifyOTPState();
|
||||||
|
|||||||
24
lib/view_model/LoginPage/Loginbloc.dart
Normal file
24
lib/view_model/LoginPage/Loginbloc.dart
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
|
import 'Loginobserver.dart';
|
||||||
|
|
||||||
|
class CounterBloc extends Bloc<CounterEvents, CounterStates> {
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
CounterBloc() : super(UpdateState(0)) {
|
||||||
|
on<NumberIncreaseEvent>(onNumberIncrease);
|
||||||
|
on<NumberDecreaseEvent>(onNumberDecrease);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onNumberIncrease(
|
||||||
|
NumberIncreaseEvent event, Emitter<CounterStates> emit) async {
|
||||||
|
counter = counter + 1;
|
||||||
|
emit(UpdateState(counter));
|
||||||
|
}
|
||||||
|
|
||||||
|
void onNumberDecrease(
|
||||||
|
NumberDecreaseEvent event, Emitter<CounterStates> emit) async {
|
||||||
|
counter = counter - 1;
|
||||||
|
emit(UpdateState(counter));
|
||||||
|
}
|
||||||
|
}
|
||||||
14
lib/view_model/LoginPage/Loginobserver.dart
Normal file
14
lib/view_model/LoginPage/Loginobserver.dart
Normal file
@@ -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);
|
||||||
|
}
|
||||||
24
lib/view_model/SendOtp/sendOtpObserver.dart
Normal file
24
lib/view_model/SendOtp/sendOtpObserver.dart
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
// Define events
|
||||||
|
abstract class SendOtpEvent {
|
||||||
|
const SendOtpEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SendOtp extends SendOtpEvent {
|
||||||
|
final Map<String, String> loginData;
|
||||||
|
SendOtp(this.loginData){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [loginData];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define states
|
||||||
|
enum SendOtpState { initial, loading, success, failure }
|
||||||
|
|
||||||
33
lib/view_model/SendOtp/sendOtpbloc.dart
Normal file
33
lib/view_model/SendOtp/sendOtpbloc.dart
Normal file
@@ -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<SendOtpEvent, SendOtpState> {
|
||||||
|
SendOtpBloc() : super(SendOtpState.initial) {
|
||||||
|
on<SendOtp>(mapEventToState);
|
||||||
|
}
|
||||||
|
Future<void> mapEventToState(
|
||||||
|
SendOtp event, Emitter<SendOtpState> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
24
pubspec.lock
24
pubspec.lock
@@ -49,6 +49,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.2"
|
version: "2.0.2"
|
||||||
|
bloc:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: bloc
|
||||||
|
sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "8.1.4"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -217,6 +225,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.3.9"
|
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:
|
expansion_tile_group:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -318,6 +334,14 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
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:
|
flutter_branch_sdk:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ dependencies:
|
|||||||
audio_video_progress_bar: ^2.0.2
|
audio_video_progress_bar: ^2.0.2
|
||||||
syncfusion_flutter_pdfviewer:
|
syncfusion_flutter_pdfviewer:
|
||||||
flutter_html: ^3.0.0-beta.2
|
flutter_html: ^3.0.0-beta.2
|
||||||
|
flutter_bloc: ^8.1.5
|
||||||
|
equatable: ^2.0.5
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user