Skip to content

Commit

Permalink
otp auth done
Browse files Browse the repository at this point in the history
  • Loading branch information
RGTechPro committed Aug 13, 2022
1 parent 537eb12 commit 24c15b6
Show file tree
Hide file tree
Showing 15 changed files with 507 additions and 57 deletions.
15 changes: 11 additions & 4 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ if (flutterVersionName == null) {

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 31
ndkVersion flutter.ndkVersion

compileOptions {
Expand All @@ -44,13 +45,15 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.mera_aadhar"
applicationId "com.shark.mera_aadhar"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
minSdkVersion 19
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true

}

buildTypes {
Expand All @@ -68,4 +71,8 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:30.3.2')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.android.support:multidex:1.0.3'
}
39 changes: 39 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "800240519039",
"project_id": "sportyme-9927c",
"storage_bucket": "sportyme-9927c.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:800240519039:android:5b337449d5e254a151bc4a",
"android_client_info": {
"package_name": "com.shark.mera_aadhar"
}
},
"oauth_client": [
{
"client_id": "800240519039-1eti7eqvbvgl9qj60s62sfevt9utsutn.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCy24LszFzZ92VaIuL9CR0fid13JXBZLgw"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "800240519039-1eti7eqvbvgl9qj60s62sfevt9utsutn.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
2 changes: 1 addition & 1 deletion android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mera_aadhar">
package="com.shark.mera_aadhar">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mera_aadhar">
package="com.shark.mera_aadhar">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.mera_aadhar
package com.shark.mera_aadhar

import io.flutter.embedding.android.FlutterActivity

Expand Down
2 changes: 1 addition & 1 deletion android/app/src/profile/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mera_aadhar">
package="com.shark.mera_aadhar">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
Expand Down
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.13'
}
}

Expand Down
21 changes: 13 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
import 'package:mera_aadhar/screens/home_page.dart';
import 'package:mera_aadhar/screens/verification.dart';
import 'package:mera_aadhar/services/auth/otp_signin.dart';
import 'package:provider/provider.dart';
import 'package:firebase_core/firebase_core.dart';

void main() {
void main()async { WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}

Expand All @@ -12,14 +16,15 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'मेरा Aadhar',
theme: ThemeData(

primarySwatch: Colors.blue,
return MultiProvider(
providers: [ChangeNotifierProvider(create: (context) => Auth())],
child: MaterialApp(
title: 'मेरा Aadhar',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
),
home:HomePage(),
);
}
}

8 changes: 8 additions & 0 deletions lib/screens/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/material.dart';
import 'package:mera_aadhar/screens/login_type.dart';
import 'package:mera_aadhar/screens/verification.dart';
import 'package:mera_aadhar/services/auth/otp_signin.dart';
import 'package:mera_aadhar/utilities/constants.dart';
import 'package:mera_aadhar/screens/map_basic.dart';
import 'package:provider/provider.dart';

class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
Expand All @@ -30,6 +32,12 @@ class HomePage extends StatelessWidget {
MaterialPageRoute(builder: (context) => LiveLocationPage()));
},
),
TextButton(
child: Text("Logout"),
onPressed: () {
Provider.of<Auth>(context,listen: false).logout(context);
},
),
],
),
));
Expand Down
151 changes: 112 additions & 39 deletions lib/screens/verification.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'package:flutter/services.dart';
import 'package:flutter/src/foundation/key.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/material.dart';
import 'package:intl_phone_field/intl_phone_field.dart';
import 'package:mera_aadhar/services/auth/otp_signin.dart';
import 'package:mera_aadhar/utilities/constants.dart';
import 'package:flutter_otp_text_field/flutter_otp_text_field.dart';

import 'package:provider/provider.dart';
import 'package:otp_autofill/otp_autofill.dart';
class Verification extends StatefulWidget {
const Verification({Key? key}) : super(key: key);

Expand All @@ -13,10 +16,29 @@ class Verification extends StatefulWidget {
}

class _VerificationState extends State<Verification> {
final _formKey = GlobalKey<FormState>();

FocusNode mobileNumberFocusNode = FocusNode();
FocusNode otpFocusNode = FocusNode();
bool isOTPScreen = false;
@override
void initState(){
super.initState();
OTPInteractor().getAppSignature()
.then((value) => print('signature - $value'));
final controller = OTPTextEditController(
codeLength: 6,
onCodeReceive: (code) => print('Your Application receive code - $code'),
)..startListenUserConsent(
(code) {
final exp = RegExp(r'(\d{6})');
return exp.stringMatch(code ?? '') ?? '';
},

);
}
@override

Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
Expand Down Expand Up @@ -59,36 +81,52 @@ class _VerificationState extends State<Verification> {
if (!isOTPScreen)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 35),
child: Focus(
onFocusChange: (hasFocus) {
setState(() {});
},
child: IntlPhoneField(
dropdownIcon: Icon(
Icons.arrow_drop_down,
color: mobileNumberFocusNode.hasFocus
child: Form(
autovalidateMode: AutovalidateMode.onUserInteraction,
key: _formKey,
child: Focus(
onFocusChange: (hasFocus) {
setState(() {});
},
child: IntlPhoneField(

onChanged: (value) {
Provider.of<Auth>(context, listen: false).mobileNumber =
value.number;
},
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
],
validator: (value) {
// List<String> validArray=['1','2','3','4','5','6','7','8','9','0'];
},
dropdownIcon: Icon(
Icons.arrow_drop_down,
color: mobileNumberFocusNode.hasFocus
? Colors.orange
: Colors.black54,
),
cursorColor: mobileNumberFocusNode.hasFocus
? Colors.orange
: Colors.black54,
focusNode: mobileNumberFocusNode,
decoration: InputDecoration(
fillColor: Color(0xFFF3F5F5),
filled: true,
counterText: '',
labelStyle: TextStyle(
color: mobileNumberFocusNode.hasFocus
? Colors.orange
: Colors.black54),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius:
BorderRadius.all(Radius.circular(10))),
labelText: 'Phone Number',
),
flagsButtonPadding: EdgeInsets.symmetric(horizontal: 5),
initialCountryCode: 'IN',
),
cursorColor: mobileNumberFocusNode.hasFocus
? Colors.orange
: Colors.black54,
focusNode: mobileNumberFocusNode,
decoration: InputDecoration(
fillColor: Color(0xFFF3F5F5),
filled: true,
counterText: '',
labelStyle: TextStyle(
color: mobileNumberFocusNode.hasFocus
? Colors.orange
: Colors.black54),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.all(Radius.circular(10))),
labelText: 'Phone Number',
),
flagsButtonPadding: EdgeInsets.symmetric(horizontal: 5),
initialCountryCode: 'IN',
),
),
),
Expand All @@ -98,6 +136,11 @@ class _VerificationState extends State<Verification> {
child: Focus(
focusNode: otpFocusNode,
child: OtpTextField(

onSubmit: (value) {
Provider.of<Auth>(context, listen: false).otp = value;
print(value);
},
cursorColor:
otpFocusNode.hasFocus ? Colors.orange : Colors.black54,
borderRadius: BorderRadius.all(Radius.circular(15)),
Expand Down Expand Up @@ -134,17 +177,47 @@ class _VerificationState extends State<Verification> {
SizedBox(
width: 275,
height: 40,
child: TextButton(
style: buttonStyle,
onPressed: () {
setState(() {
isOTPScreen = true;
});
},
child: Text(
(!isOTPScreen) ? 'SEND OTP' : 'VERIFY',
style: buttonTextStyle,
)),
child: !Provider.of<Auth>(context).isLoading
? TextButton(
style: buttonStyle,
onPressed: () async {
int flag = 0;
if (!isOTPScreen && _formKey.currentState!.validate()) {
setState(() {
Provider.of<Auth>(context, listen: false)
.isLoading = true;
});
await Provider.of<Auth>(context, listen: false)
.submitPhoneNumber(context);
setState(() {
Provider.of<Auth>(context, listen: false)
.isLoading = false;
isOTPScreen = true;
flag = 1;
});
}
if (isOTPScreen&&flag==0) {
setState(() {
Provider.of<Auth>(context, listen: false)
.isLoading = true;
});
await Provider.of<Auth>(context, listen: false)
.submitOTP(context);
setState(() {
Provider.of<Auth>(context, listen: false)
.isLoading = false;
});
}
},
child: Text(
(!isOTPScreen) ? 'SEND OTP' : 'VERIFY',
style: buttonTextStyle,
))
: Center(
child: CircularProgressIndicator(
color: Colors.redAccent,
),
),
)
],
),
Expand Down
Loading

0 comments on commit 24c15b6

Please sign in to comment.