3. import asset, proses login google mail

This commit is contained in:
sindhu
2024-01-09 09:30:42 +07:00
parent 85a21f80b7
commit e686c6f7a1
19 changed files with 655 additions and 110 deletions

View File

@@ -0,0 +1,213 @@
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),
),
),
),
),
),
),
),
],
),
),
),
);
}
}

View File

@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import '../../app/constant.dart';
class SplashScreen extends StatelessWidget {
const SplashScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: ListView(
children: [
Container(
// width: Constant.getActualXPhone(context: context, x: 390),
height: Constant.getActualYPhone(context: context, y: 844),
decoration: BoxDecoration(
color: Colors.blue, // Ganti dengan warna dan gambar yang sesuai
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage(
'images/background_splash.png'), // Ganti dengan path gambar yang diinginkan
),
),
child: Align(
alignment: Alignment.center,
child: Container(
width: Constant.getActualXPhone(context: context, x: 200),
height: Constant.getActualYPhone(context: context, y: 200),
decoration: BoxDecoration(
// color: Colors.green,
image: DecorationImage(
// fit: BoxFit.contain,
image: AssetImage('images/logo_sismedika_rectangle.png'),
),
),
),
),
),
],
),
),
);
}
}