2022-09-20 16:32:46 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-21 16:11:23 +02:00
|
|
|
import 'package:flutter_login/backend/login_repository.dart';
|
2022-09-20 16:32:46 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../../flutter_login_view.dart';
|
|
|
|
|
|
|
|
class LoginSocialButtons extends StatelessWidget {
|
|
|
|
const LoginSocialButtons({
|
|
|
|
required this.navigateRegistration,
|
|
|
|
required this.navigateLogin,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final Function navigateRegistration;
|
|
|
|
final Function navigateLogin;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var config = FlutterLogin.of(context).config;
|
2022-09-21 16:11:23 +02:00
|
|
|
var repository = context.loginRepository() as LoginRepositoryWithSocial;
|
2022-09-20 16:32:46 +02:00
|
|
|
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: List.generate(
|
|
|
|
config.loginOptions.socialOptions.socialLogins.length,
|
|
|
|
(index) {
|
|
|
|
var method = config.loginOptions.socialOptions.socialLogins[index];
|
|
|
|
var padding = 0.0;
|
|
|
|
var sidePadding = MediaQuery.of(context).size.width / 4;
|
|
|
|
if (index <
|
|
|
|
config.loginOptions.socialOptions.socialLogins.length - 1) {
|
|
|
|
padding = 15;
|
|
|
|
}
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: padding,
|
|
|
|
left: sidePadding,
|
|
|
|
right: sidePadding,
|
|
|
|
),
|
|
|
|
child: config.appTheme.buttons.secondaryButton(
|
|
|
|
context: context,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 10,
|
|
|
|
horizontal: 10,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
_iconDataForSocial(method, context),
|
|
|
|
size: 24,
|
|
|
|
color: Theme.of(context).buttonTheme.colorScheme?.primary,
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 20),
|
|
|
|
child: Text(
|
|
|
|
context.translate(
|
|
|
|
method.toString(),
|
|
|
|
defaultValue: method
|
|
|
|
.toString()
|
|
|
|
.replaceAll('SocialLoginMethod.', ''),
|
|
|
|
),
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
style: Theme.of(context).textTheme.button!.copyWith(
|
|
|
|
fontSize: 16,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.buttonTheme
|
|
|
|
.colorScheme
|
|
|
|
?.primary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
2022-09-21 10:03:08 +02:00
|
|
|
var user = await repository.signInWithSocial(
|
2022-09-20 16:32:46 +02:00
|
|
|
SocialLoginBundle(
|
|
|
|
method: method,
|
|
|
|
interactionType: SocialInteractionType.Login,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
var prefs = await SharedPreferences.getInstance();
|
|
|
|
await prefs.setBool('autoLogin', true);
|
|
|
|
if (user != null) {
|
2022-09-21 10:03:08 +02:00
|
|
|
if (await repository.isRegistrationRequired(user)) {
|
2022-09-20 16:32:46 +02:00
|
|
|
navigateRegistration();
|
|
|
|
} else {
|
|
|
|
navigateLogin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
IconData? _iconDataForSocial(SocialLoginMethod method, BuildContext context) {
|
|
|
|
switch (method) {
|
|
|
|
case SocialLoginMethod.Google:
|
2022-09-21 10:03:08 +02:00
|
|
|
return context.login().config.appTheme.icons.google;
|
2022-09-20 16:32:46 +02:00
|
|
|
case SocialLoginMethod.FaceBook:
|
2022-09-21 10:03:08 +02:00
|
|
|
return context.login().config.appTheme.icons.facebook;
|
2022-09-20 16:32:46 +02:00
|
|
|
case SocialLoginMethod.Apple:
|
2022-09-21 10:03:08 +02:00
|
|
|
return context.login().config.appTheme.icons.apple;
|
2022-09-20 16:32:46 +02:00
|
|
|
case SocialLoginMethod.LinkedIn:
|
2022-09-21 10:03:08 +02:00
|
|
|
return context.login().config.appTheme.icons.linkedIn;
|
2022-09-20 16:32:46 +02:00
|
|
|
case SocialLoginMethod.Microsoft:
|
2022-09-21 10:03:08 +02:00
|
|
|
return context.login().config.appTheme.icons.microsoft;
|
2022-09-20 16:32:46 +02:00
|
|
|
case SocialLoginMethod.Twitter:
|
2022-09-21 10:03:08 +02:00
|
|
|
return context.login().config.appTheme.icons.twitter;
|
2022-09-20 16:32:46 +02:00
|
|
|
case SocialLoginMethod.Custom:
|
2022-09-21 10:03:08 +02:00
|
|
|
return context.login().config.appTheme.icons.customSocial;
|
2022-09-20 16:32:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|