Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google authentication #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -36,10 +36,11 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "dev.hireflutter.starterKit"
minSdkVersion 16
minSdkVersion 19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to increase the version of minSdkVersion?

targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

buildTypes {
Expand All @@ -59,4 +60,5 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:28.2.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation("androidx.multidex:multidex:2.0.1")
}
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
jcenter()
Expand Down
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hf_flutter_starter_kit/src/app.dart';
import 'package:hf_flutter_starter_kit/src/app/feature/google_authenticaiton/data/observers/app_bloc_observer.dart';

import 'src/injection/setup_locator.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

Bloc.observer = AppBlocObserver();
setup();
runApp(App());
}
21 changes: 19 additions & 2 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:hf_flutter_starter_kit/src/app/feature/google_authenticaiton/bloc/authentication_bloc.dart';
import 'package:hf_flutter_starter_kit/src/app/feature/google_authenticaiton/data/domain/google_sign_in_provider.dart';
import 'package:provider/provider.dart';

import 'app/feature/authentication/presentation/viewmodel/auth_view_model.dart';
import 'app/feature/google_authenticaiton/data/domain/authentication_firebase_provider.dart';
import 'app/feature/google_authenticaiton/data/repositories/authenticaiton_repository.dart';
import 'app/router/router.gr.dart';
import 'config/theme_config.dart';

Expand All @@ -12,13 +19,23 @@ class App extends StatelessWidget {

@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<AuthViewModel>(
return BlocProvider<AuthenticationBloc>(create:(context) => AuthenticationBloc(
authenticationRepository: AuthenticationRepository(
authenticationFirebaseProvider: AuthenticationFirebaseProvider(
firebaseAuth: FirebaseAuth.instance,
),
googleSignInProvider: GoogleSignInProvider(
googleSignIn: GoogleSignIn(),
),
),
),
child: ChangeNotifierProvider<AuthViewModel>(
create: (context) => AuthViewModel(),
child: MaterialApp.router(
theme: ThemeConfig.lightTheme,
routerDelegate: _appRouter.delegate(),
routeInformationParser: _appRouter.defaultRouteParser(),
),
);
));
}
}
268 changes: 168 additions & 100 deletions lib/src/app/feature/authentication/presentation/login_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'package:authentication_data/authentication_data.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hf_flutter_starter_kit/src/config/color_config.dart';
import 'package:provider/provider.dart';

import '../../../router/router_constant.dart';
import '../../google_authenticaiton/bloc/authentication_bloc.dart';
import 'viewmodel/auth_view_model.dart';
import 'widgets/widgets.dart';
import 'package:auto_route/auto_route.dart';
Expand Down Expand Up @@ -156,116 +159,181 @@ class _LoginScreenState extends State<LoginScreen> {
}

return Scaffold(
body: Padding(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the build method is getting too long, I think we should break it down into smaller parts (widgets or methods as suitable depending on the case).

padding: EdgeInsets.only(
top: MediaQuery.of(context).padding.top,
left: width / 10,
right: width / 10,
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: height / 7,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: width * 0.05),
child: const Logo(),
),
SizedBox(
height: height * 0.1,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
),
height: height / 13,
width: 8 * (width / 10),
padding: const EdgeInsets.all(5),
child: Row(
body: Builder(builder: (context) {
return BlocConsumer<AuthenticationBloc, AuthenticationState>(
buildWhen: (current, next) {
if (next is AuthenticationSuccess) {
return false;
}
return true;
},
builder: (context, state) {
if (state is AuthenticationInitial ||
state is AuthenticationFailiure) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Flexible(
flex: 2,
child: FittedBox(
child: Material(
child: InkWell(
onTap: () async {
_contryCodeDialogue();
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
width: width * 0.01,
),
Text(
'+' +
(dialCodes[_selectedDialCode]['number'] ??
''),
style: Theme.of(context)
.textTheme
.bodyText1
?.copyWith(color: Styleguide.main),
),
const Icon(Icons.arrow_drop_down),
],
),
),
),
Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).padding.top,
left: width / 10,
right: width / 10,
),
),
Flexible(
flex: 7,
child: SizedBox(
height: height / 13,
child: TextFormField(
decoration: const InputDecoration(
hintText: 'Phone number',
),
controller: _controller,
cursorWidth: 3,
style: Theme.of(context)
.textTheme
.headline3
?.copyWith(color: Styleguide.main),
keyboardType: TextInputType.phone,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: height / 7,
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: width * 0.05),
child: const Logo(),
),
SizedBox(
height: height * 0.1,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
),
height: height / 13,
width: 8 * (width / 10),
padding: const EdgeInsets.all(5),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Flexible(
flex: 2,
child: FittedBox(
child: Material(
child: InkWell(
onTap: () async {
_contryCodeDialogue();
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
width: width * 0.01,
),
Text(
'+' +
(dialCodes[_selectedDialCode]
['number'] ??
''),
style: Theme.of(context)
.textTheme
.bodyText1
?.copyWith(
color: Styleguide.main),
),
const Icon(Icons.arrow_drop_down),
],
),
),
),
),
),
Flexible(
flex: 7,
child: SizedBox(
height: height / 13,
child: TextFormField(
decoration: const InputDecoration(
hintText: 'Phone number',
),
controller: _controller,
cursorWidth: 3,
style: Theme.of(context)
.textTheme
.headline3
?.copyWith(color: Styleguide.main),
keyboardType: TextInputType.phone,
),
),
),
],
),
),
SizedBox(
height: height * 0.05,
),
AppButton(
height: height / 13,
width: 8 * (width / 10),
onPressed: () {
if (_controller.text.isNotEmpty) {
/// Assign the value of [phoneNumber]
final AuthViewModel authViewModel =
Provider.of(context, listen: false);
authViewModel.setphoneNumber('+' +
dialCodes[_selectedDialCode]['number']! +
' ' +
_controller.text);
context.router
.push(const LoginVerifyScreen());
}
},
child: Text(
'SEND OTP',
style: Theme.of(context).textTheme.headline4,
),
),
Text("Or", style: Theme.of(context)
.textTheme
.headline5
?.copyWith(
color: (Styleguide.colorTransparent),
)),
AppButton(
height: height / 17,
onPressed: () =>
BlocProvider.of<AuthenticationBloc>(context)
.add(
AuthenticationGoogleStarted(),
),
child: Text('Login with Google',
style: Theme.of(context)
.textTheme
.headline5
?.copyWith(
color: (Styleguide.colorTransparent),
),
),
),
],
),
),
),

],
),
),
SizedBox(
height: height * 0.05,
),
AppButton(
height: height / 13,
width: 8 * (width / 10),
onPressed: () {
if (_controller.text.isNotEmpty) {
/// Assign the value of [phoneNumber]
final AuthViewModel authViewModel =
Provider.of(context, listen: false);
authViewModel.setphoneNumber('+' +
dialCodes[_selectedDialCode]['number']! +
' ' +
_controller.text);
context.router.push(const LoginVerifyScreen());
}
},
child: Text(
'SEND OTP',
style: Theme.of(context).textTheme.headline4,
);
} else if (state is AuthenticationLoading) {
return const Center(child: CircularProgressIndicator());
}
return Center(
child: Text('Undefined state : ${state.runtimeType}'));
},
listener: (context, state) {
if (state is AuthenticationSuccess) {
context.router.pushNamed(RouterConstant.homescreen);
} else if (state is AuthenticationFailiure) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message),
),
),
],
),
),
),
);
}
},
);
}),
);
}
}
Loading