feat: login gmail
This commit is contained in:
parent
8b1b3e950f
commit
9e2304990c
|
@ -0,0 +1,14 @@
|
||||||
|
class LoginGmailModel {
|
||||||
|
String idToken;
|
||||||
|
String accessToken;
|
||||||
|
|
||||||
|
LoginGmailModel({
|
||||||
|
required this.idToken,
|
||||||
|
required this.accessToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, String> toJson() => {
|
||||||
|
"idToken": idToken,
|
||||||
|
"accessToken": accessToken,
|
||||||
|
};
|
||||||
|
}
|
|
@ -5,9 +5,10 @@ import 'package:cims_apps/application/theme/color_palette.dart';
|
||||||
import 'package:cims_apps/core/route/route.dart';
|
import 'package:cims_apps/core/route/route.dart';
|
||||||
import 'package:cims_apps/core/utils/size_config.dart';
|
import 'package:cims_apps/core/utils/size_config.dart';
|
||||||
import 'package:cims_apps/features/auth/login/view/login_view.dart';
|
import 'package:cims_apps/features/auth/login/view/login_view.dart';
|
||||||
import 'package:cims_apps/features/auth/registration/view/initial_registration_step.dart';
|
|
||||||
import 'package:cims_apps/features/auth/registration/view/registration_view.dart';
|
import 'package:cims_apps/features/auth/registration/view/registration_view.dart';
|
||||||
|
import 'package:cims_apps/features/dashboard/dashboard_public/viewmodel/dashboard_public_viewmodel.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class DashboardPublicView extends StatelessWidget {
|
class DashboardPublicView extends StatelessWidget {
|
||||||
static const routeName = '/DashboardPublicView';
|
static const routeName = '/DashboardPublicView';
|
||||||
|
@ -37,88 +38,95 @@ class DashboardPublicView extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return ChangeNotifierProvider(
|
||||||
body: SingleChildScrollView(
|
create: (context) => DashboardPublicViewModel(),
|
||||||
padding: const EdgeInsets.only(
|
builder: (context, child) {
|
||||||
top: 32.0,
|
return Scaffold(
|
||||||
bottom: 8.0,
|
body: SingleChildScrollView(
|
||||||
left: 24.0,
|
padding: const EdgeInsets.only(
|
||||||
right: 24.0,
|
top: 32.0,
|
||||||
),
|
bottom: 8.0,
|
||||||
child: Column(
|
left: 24.0,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
right: 24.0,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
ImageView(
|
|
||||||
image: PathAssets.icon1,
|
|
||||||
width: SizeConfig.width * .35,
|
|
||||||
),
|
|
||||||
Align(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
heightFactor: 1,
|
|
||||||
child: _caption()),
|
|
||||||
Align(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: ImageView(
|
|
||||||
image: PathAssets.imgDashboard,
|
|
||||||
width: SizeConfig.width * .7,
|
|
||||||
),
|
),
|
||||||
|
child: Consumer<DashboardPublicViewModel>(
|
||||||
|
builder: (context, provider, child) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
ImageView(
|
||||||
|
image: PathAssets.icon1,
|
||||||
|
width: SizeConfig.width * .35,
|
||||||
|
),
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
heightFactor: 1,
|
||||||
|
child: _caption()),
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: ImageView(
|
||||||
|
image: PathAssets.imgDashboard,
|
||||||
|
width: SizeConfig.width * .7,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
ButtonView(
|
||||||
|
name: 'Sign in',
|
||||||
|
isOutlined: true,
|
||||||
|
width: SizeConfig.width * .43,
|
||||||
|
height: SizeConfig.height * .06,
|
||||||
|
onPressed: () {
|
||||||
|
routePush(context, page: const LoginView());
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ButtonView(
|
||||||
|
name: 'Sign Up',
|
||||||
|
width: SizeConfig.width * .43,
|
||||||
|
height: SizeConfig.height * .06,
|
||||||
|
onPressed: () {
|
||||||
|
routePush(context, page: const RegistrationView());
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const ImageView(image: PathAssets.iconConnect),
|
||||||
|
ButtonView(
|
||||||
|
name: 'Google',
|
||||||
|
isSecondaryColor: true,
|
||||||
|
isOutlined: true,
|
||||||
|
prefixIcon: const ImageView(
|
||||||
|
image: PathAssets.iconGoogle,
|
||||||
|
width: 26,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
provider.loginGoogle(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
ImageView(
|
||||||
|
image: PathAssets.iconOjk,
|
||||||
|
width: SizeConfig.width * .20,
|
||||||
|
),
|
||||||
|
ImageView(
|
||||||
|
image: PathAssets.iconInklusi,
|
||||||
|
width: SizeConfig.width * .20,
|
||||||
|
),
|
||||||
|
ImageView(
|
||||||
|
image: PathAssets.iconReksadana,
|
||||||
|
width: SizeConfig.width * .20,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
Row(
|
);
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
});
|
||||||
children: [
|
|
||||||
ButtonView(
|
|
||||||
name: 'Sign in',
|
|
||||||
isOutlined: true,
|
|
||||||
width: SizeConfig.width * .43,
|
|
||||||
height: SizeConfig.height * .06,
|
|
||||||
onPressed: () {
|
|
||||||
routePush(context, page: const LoginView());
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ButtonView(
|
|
||||||
name: 'Sign Up',
|
|
||||||
width: SizeConfig.width * .43,
|
|
||||||
height: SizeConfig.height * .06,
|
|
||||||
onPressed: () {
|
|
||||||
routePush(context, page: const RegistrationView());
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const ImageView(image: PathAssets.iconConnect),
|
|
||||||
ButtonView(
|
|
||||||
name: 'Google',
|
|
||||||
isSecondaryColor: true,
|
|
||||||
isOutlined: true,
|
|
||||||
prefixIcon: const ImageView(
|
|
||||||
image: PathAssets.iconGoogle,
|
|
||||||
width: 26,
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
routePush(context, page: const InitialRegistrationStep());
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
ImageView(
|
|
||||||
image: PathAssets.iconOjk,
|
|
||||||
width: SizeConfig.width * .20,
|
|
||||||
),
|
|
||||||
ImageView(
|
|
||||||
image: PathAssets.iconInklusi,
|
|
||||||
width: SizeConfig.width * .20,
|
|
||||||
),
|
|
||||||
ImageView(
|
|
||||||
image: PathAssets.iconReksadana,
|
|
||||||
width: SizeConfig.width * .20,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
import 'package:cims_apps/core/route/route.dart';
|
||||||
|
import 'package:cims_apps/features/auth/registration/view/initial_registration_step.dart';
|
||||||
|
import 'package:cims_apps/features/dashboard/dashboard_public/model/login_gmail_model.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:google_sign_in/google_sign_in.dart';
|
||||||
|
|
||||||
|
class DashboardPublicViewModel extends ChangeNotifier {
|
||||||
|
String emailGoogle = '';
|
||||||
|
final GoogleSignIn googleSignIn = GoogleSignIn(
|
||||||
|
scopes: [
|
||||||
|
'email',
|
||||||
|
'https://www.googleapis.com/auth/contacts.readonly',
|
||||||
|
],
|
||||||
|
);
|
||||||
|
Future<LoginGmailModel?> _getGmail() async {
|
||||||
|
LoginGmailModel? loginGmailModel;
|
||||||
|
try {
|
||||||
|
final signInResult = await googleSignIn.signIn();
|
||||||
|
if (signInResult != null) {
|
||||||
|
emailGoogle = signInResult.email;
|
||||||
|
final signInAuth = await signInResult.authentication;
|
||||||
|
final accessToken = signInAuth.accessToken;
|
||||||
|
final idToken = signInAuth.idToken;
|
||||||
|
if (idToken != null && accessToken != null) {
|
||||||
|
loginGmailModel = LoginGmailModel(
|
||||||
|
accessToken: accessToken,
|
||||||
|
idToken: idToken,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('catch error $e');
|
||||||
|
}
|
||||||
|
return loginGmailModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> loginGoogle(BuildContext context) async {
|
||||||
|
bool loginSuccess = false;
|
||||||
|
loginSuccess = await _getGmail().then((payload) async {
|
||||||
|
bool result = false;
|
||||||
|
if (payload != null) {
|
||||||
|
debugPrint('objectzz ${payload.toJson()}');
|
||||||
|
routePush(context, page: InitialRegistrationStep());
|
||||||
|
googleSignIn.disconnect();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
return loginSuccess;
|
||||||
|
}
|
||||||
|
}
|
48
pubspec.lock
48
pubspec.lock
|
@ -264,6 +264,54 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
google_identity_services_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: google_identity_services_web
|
||||||
|
sha256: "0c56c2c5d60d6dfaf9725f5ad4699f04749fb196ee5a70487a46ef184837ccf6"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.3.0+2"
|
||||||
|
google_sign_in:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: google_sign_in
|
||||||
|
sha256: "0b8787cb9c1a68ad398e8010e8c8766bfa33556d2ab97c439fb4137756d7308f"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "6.2.1"
|
||||||
|
google_sign_in_android:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: google_sign_in_android
|
||||||
|
sha256: bfd42c81c30c6faba16e0f62968d5505a87504aaa672b3155ee931461abb0a49
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "6.1.21"
|
||||||
|
google_sign_in_ios:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: google_sign_in_ios
|
||||||
|
sha256: f3336d9e44d4d28063ac90271f6db5caf99f0480cb07281330e7a432edb95226
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "5.7.3"
|
||||||
|
google_sign_in_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: google_sign_in_platform_interface
|
||||||
|
sha256: "1f6e5787d7a120cc0359ddf315c92309069171306242e181c09472d1b00a2971"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.4.5"
|
||||||
|
google_sign_in_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: google_sign_in_web
|
||||||
|
sha256: a278ea2d01013faf341cbb093da880d0f2a552bbd1cb6ee90b5bebac9ba69d77
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.12.3+2"
|
||||||
group_button:
|
group_button:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -52,6 +52,7 @@ dependencies:
|
||||||
dotted_border: ^2.1.0
|
dotted_border: ^2.1.0
|
||||||
shared_preferences: ^2.2.2
|
shared_preferences: ^2.2.2
|
||||||
calendar_date_picker2: ^0.5.3
|
calendar_date_picker2: ^0.5.3
|
||||||
|
google_sign_in: ^6.2.1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user