diff --git a/lib/features/dashboard/dashboard_public/model/login_gmail_model.dart b/lib/features/dashboard/dashboard_public/model/login_gmail_model.dart new file mode 100644 index 0000000..805d352 --- /dev/null +++ b/lib/features/dashboard/dashboard_public/model/login_gmail_model.dart @@ -0,0 +1,14 @@ +class LoginGmailModel { + String idToken; + String accessToken; + + LoginGmailModel({ + required this.idToken, + required this.accessToken, + }); + + Map toJson() => { + "idToken": idToken, + "accessToken": accessToken, + }; +} diff --git a/lib/features/dashboard/dashboard_public/view/dashboard_public_view.dart b/lib/features/dashboard/dashboard_public/view/dashboard_public_view.dart index 8645822..aa9d85c 100644 --- a/lib/features/dashboard/dashboard_public/view/dashboard_public_view.dart +++ b/lib/features/dashboard/dashboard_public/view/dashboard_public_view.dart @@ -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/utils/size_config.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/dashboard/dashboard_public/viewmodel/dashboard_public_viewmodel.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; class DashboardPublicView extends StatelessWidget { static const routeName = '/DashboardPublicView'; @@ -37,88 +38,95 @@ class DashboardPublicView extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - body: SingleChildScrollView( - padding: const EdgeInsets.only( - top: 32.0, - bottom: 8.0, - left: 24.0, - right: 24.0, - ), - child: 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, + return ChangeNotifierProvider( + create: (context) => DashboardPublicViewModel(), + builder: (context, child) { + return Scaffold( + body: SingleChildScrollView( + padding: const EdgeInsets.only( + top: 32.0, + bottom: 8.0, + left: 24.0, + right: 24.0, ), + child: Consumer( + 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, - ), - ], - ) - ], - ), - ), - ); + ); + }); } } diff --git a/lib/features/dashboard/dashboard_public/viewmodel/dashboard_public_viewmodel.dart b/lib/features/dashboard/dashboard_public/viewmodel/dashboard_public_viewmodel.dart new file mode 100644 index 0000000..89ebd5a --- /dev/null +++ b/lib/features/dashboard/dashboard_public/viewmodel/dashboard_public_viewmodel.dart @@ -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 _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 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; + } +} diff --git a/pubspec.lock b/pubspec.lock index 6fd9b82..f811a80 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -264,6 +264,54 @@ packages: description: flutter source: sdk 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: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 2ce93d1..cb05aa4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -52,6 +52,7 @@ dependencies: dotted_border: ^2.1.0 shared_preferences: ^2.2.2 calendar_date_picker2: ^0.5.3 + google_sign_in: ^6.2.1