214 lines
7.4 KiB
Dart
214 lines
7.4 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:google_sign_in/google_sign_in.dart';
|
|
|
|
import '../../app/constant.dart';
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
const LoginScreen({super.key});
|
|
|
|
@override
|
|
State<LoginScreen> createState() => _LoginScreenState();
|
|
}
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
GoogleSignInAccount? _currentUser;
|
|
final GoogleSignIn _googleSignIn = GoogleSignIn(
|
|
scopes: [
|
|
'email',
|
|
'https://www.googleapis.com/auth/contacts.readonly',
|
|
],
|
|
);
|
|
|
|
@override
|
|
void initState() {
|
|
_googleSignIn.onCurrentUserChanged.listen((account) {
|
|
setState(() {
|
|
_currentUser = account;
|
|
});
|
|
});
|
|
_googleSignIn.signInSilently();
|
|
super.initState();
|
|
}
|
|
|
|
Future<void> _handleSignIn() async {
|
|
try {
|
|
await _googleSignIn.signIn();
|
|
} catch (error) {
|
|
if (kDebugMode) {
|
|
print(error);
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
height: Constant.getActualYPhone(context: context, y: 100),
|
|
),
|
|
_currentUser != null
|
|
? Container(
|
|
child: ListTile(
|
|
leading: GoogleUserCircleAvatar(
|
|
identity: _currentUser!,
|
|
),
|
|
title: Text(
|
|
_currentUser!.displayName ?? "",
|
|
),
|
|
subtitle: Text(
|
|
_currentUser!.email,
|
|
),
|
|
trailing: IconButton(
|
|
icon: Icon(Icons.logout_outlined),
|
|
onPressed: () async {
|
|
await _googleSignIn.disconnect();
|
|
},
|
|
),
|
|
),
|
|
)
|
|
:
|
|
// Logo Landscape
|
|
Padding(
|
|
padding: EdgeInsets.only(
|
|
top: Constant.getActualYPhone(context: context, y: 120),
|
|
left: Constant.getActualXPhone(context: context, x: 91),
|
|
right:
|
|
Constant.getActualXPhone(context: context, x: 90),
|
|
// bottom: Constant.getActualYPhone(context: context, y: y)
|
|
),
|
|
child: Container(
|
|
width:
|
|
Constant.getActualXPhone(context: context, x: 209),
|
|
height:
|
|
Constant.getActualYPhone(context: context, y: 70),
|
|
decoration: BoxDecoration(
|
|
// color: Colors.green,
|
|
image: DecorationImage(
|
|
// fit: BoxFit.contain,
|
|
image: AssetImage(
|
|
'images/logo_sismedika_landscape.png'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
SizedBox(
|
|
height: Constant.getActualYPhone(context: context, y: 100),
|
|
),
|
|
|
|
// title
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
'Selamat Datang',
|
|
style: Constant.titleH1_700(context: context)
|
|
.copyWith(color: Constant.textBlack),
|
|
),
|
|
Container(
|
|
width: Constant.getActualXPhone(context: context, x: 24),
|
|
height: Constant.getActualYPhone(context: context, y: 24),
|
|
// color: Colors.redAccent,
|
|
decoration: BoxDecoration(
|
|
// color: Colors.green,
|
|
image: DecorationImage(
|
|
// fit: BoxFit.contain,
|
|
image: AssetImage('images/emoji_handshake.png'),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
SizedBox(
|
|
height: Constant.getActualYPhone(context: context, y: 7),
|
|
),
|
|
|
|
// title grey
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
'Silahkan masuk untuk mengakses akun Anda',
|
|
style: Constant.titleH2_600(context: context).copyWith(
|
|
color: Constant.textLightGrey,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
SizedBox(
|
|
height: Constant.getActualYPhone(context: context, y: 64),
|
|
),
|
|
|
|
// button login
|
|
Padding(
|
|
padding: EdgeInsets.only(
|
|
left: Constant.getActualXPhone(context: context, x: 23),
|
|
right: Constant.getActualXPhone(context: context, x: 23),
|
|
),
|
|
child: SizedBox(
|
|
width: Constant.getActualXPhone(context: context, x: 344),
|
|
height: Constant.getActualYPhone(context: context, y: 48),
|
|
child: ElevatedButton(
|
|
onPressed: () async {
|
|
await _handleSignIn();
|
|
},
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
width:
|
|
Constant.getActualXPhone(context: context, x: 24),
|
|
height:
|
|
Constant.getActualYPhone(context: context, y: 24),
|
|
decoration: BoxDecoration(
|
|
// color: Colors.green,
|
|
image: DecorationImage(
|
|
// fit: BoxFit.contain,
|
|
image: AssetImage('images/icon_google.png'),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
width:
|
|
Constant.getActualXPhone(context: context, x: 2),
|
|
),
|
|
Text(
|
|
'Continue with Google',
|
|
style: Constant.logintitle_700(context: context)
|
|
.copyWith(
|
|
color: Constant.textBlack,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
style: ButtonStyle(
|
|
backgroundColor: MaterialStateColor.resolveWith(
|
|
(st) => Colors.white,
|
|
),
|
|
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
|
RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(24),
|
|
side: BorderSide(
|
|
color: Color.fromRGBO(145, 158, 171, 0.32),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|