Make sign in screen flow cleaner on logins.

main
Hank Grabowski 2023-11-27 13:39:57 -06:00
rodzic b13b66ec48
commit ff6275d079
1 zmienionych plików z 150 dodań i 106 usunięć

Wyświetl plik

@ -47,6 +47,28 @@ class _SignInScreenState extends State<SignInScreen> {
} else {
newProfile();
}
usernameController.addListener(() {
_updateSignInButtonStatus();
});
passwordController.addListener(() {
_updateSignInButtonStatus();
});
serverNameController.addListener(() {
_updateSignInButtonStatus();
});
}
void _updateSignInButtonStatus() {
setState(() {
signInButtonEnabled = switch (oauthType) {
usernamePasswordType =>
serverNameController.text.isNotEmpty &&
usernameController.text.isNotEmpty &&
passwordController.text.isNotEmpty,
oauthType => serverNameController.text.isNotEmpty,
_ => false,
};
});
}
void newProfile() {
@ -54,7 +76,7 @@ class _SignInScreenState extends State<SignInScreen> {
passwordController.clear();
serverNameController.clear();
authType = oauthType;
signInButtonEnabled = true;
signInButtonEnabled = false;
existingProfile = null;
}
@ -152,7 +174,10 @@ class _SignInScreenState extends State<SignInScreen> {
hintText: 'Server Name (friendica.example.com)',
border: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).colorScheme.background,
color: Theme
.of(context)
.colorScheme
.background,
),
borderRadius: BorderRadius.circular(5.0),
),
@ -163,7 +188,8 @@ class _SignInScreenState extends State<SignInScreen> {
if (!showUsernameAndPasswordFields) ...[
Text(
existingAccount
? 'Configured to sign in as user ${existingProfile?.handle}'
? 'Configured to sign in as user ${existingProfile
?.handle}'
: 'Relatica will open the requested Friendica site in a web browser where you will be asked to authorize this client.',
softWrap: true,
),
@ -195,7 +221,10 @@ class _SignInScreenState extends State<SignInScreen> {
hintText: 'Username (user@example.com)',
border: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).colorScheme.background,
color: Theme
.of(context)
.colorScheme
.background,
),
borderRadius: BorderRadius.circular(5.0),
),
@ -229,7 +258,10 @@ class _SignInScreenState extends State<SignInScreen> {
hintText: 'Password',
border: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).colorScheme.background,
color: Theme
.of(context)
.colorScheme
.background,
),
borderRadius: BorderRadius.circular(5.0),
),
@ -240,14 +272,17 @@ class _SignInScreenState extends State<SignInScreen> {
],
signInButtonEnabled
? ElevatedButton(
onPressed: () => _signIn(context),
onPressed: () async => await _signIn(context),
child: const Text('Signin'),
)
: SizedBox(),
const VerticalPadding(),
Text(
'Logged out:',
style: Theme.of(context).textTheme.headlineSmall,
style: Theme
.of(context)
.textTheme
.headlineSmall,
),
loggedOutProfiles.isEmpty
? const Text(
@ -289,7 +324,10 @@ class _SignInScreenState extends State<SignInScreen> {
const VerticalPadding(),
Text(
'Logged in:',
style: Theme.of(context).textTheme.headlineSmall,
style: Theme
.of(context)
.textTheme
.headlineSmall,
),
loggedInProfiles.isEmpty
? const Text(
@ -353,7 +391,7 @@ class _SignInScreenState extends State<SignInScreen> {
);
}
void _signIn(BuildContext context) async {
Future<void> _signIn(BuildContext context) async {
final valid = formKey.currentState?.validate() ?? false;
if (!valid) {
buildSnackbar(
@ -385,13 +423,19 @@ class _SignInScreenState extends State<SignInScreen> {
return;
}
print('Sign in credentials: ${creds.toJson()}');
final result = await getIt<AccountsService>().signIn(creds);
buildSnackbar(context, 'Attempting to sign in account...');
final result = await getIt<AccountsService>().signIn(
creds,
withNotification: false,
);
if (mounted && result.isFailure) {
buildSnackbar(context, 'Error signing in: ${result.error}');
return;
}
if (mounted) {
buildSnackbar(context, 'Account signed in...');
}
await getIt<AccountsService>().setActiveProfile(result.value);
if (mounted) {
context.goNamed(ScreenPaths.timelines);