Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ui/account/unified_connect_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:forui/forui.dart';

import '../../domain/school_system.dart';
Expand Down Expand Up @@ -61,6 +62,9 @@ class _UnifiedConnectScreenState extends State<UnifiedConnectScreen> {
options: ApiClient.handled(),
);
final accountId = res.data?['accountId']?.toString();
// Only once the credentials are known good, so a manager is never asked
// to save something that did not work.
TextInput.finishAutofillContext();
if (mounted) Navigator.of(context).pop(accountId);
} catch (e) {
setState(() => _error = ApiError.describe(e));
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/private/private_connect_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:forui/forui.dart';

import '../../domain/school_system.dart';
Expand Down Expand Up @@ -102,6 +103,7 @@ class _PrivateConnectScreenState extends State<PrivateConnectScreen> {
password: password,
totpSecret: totpSecret,
));
TextInput.finishAutofillContext();
if (mounted) Navigator.of(context).pop(true);
}

Expand All @@ -118,6 +120,7 @@ class _PrivateConnectScreenState extends State<PrivateConnectScreen> {
);
await ScrapeProxyClient.instance.data(account);
await PrivateAccountStore.instance.save(account);
TextInput.finishAutofillContext();
if (mounted) Navigator.of(context).pop(true);
}

Expand Down
73 changes: 50 additions & 23 deletions lib/ui/widgets/dynamic_login_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,60 @@ class DynamicLoginForm extends StatelessWidget {
static bool _isTotp(SchoolSystemLoginField f) =>
f.type == 'totp' || f.key.toLowerCase() == 'totp';

/// What the platform needs to tell these boxes apart. The form is built from
/// the catalog, so this reads the descriptor rather than naming any school
/// system; without it a password manager sees a row of anonymous text boxes
/// and offers nothing.
static List<String> _autofillHints(SchoolSystemLoginField f) {
final key = f.key.toLowerCase();
if (f.type == 'password' || key.contains('password')) return const [AutofillHints.password];
if (f.type == 'url' || key.contains('url')) return const [AutofillHints.url];
if (f.type == 'email' || key.contains('email') || key.contains('mail')) {
return const [AutofillHints.username, AutofillHints.email];
}
if (key.contains('user') || key.contains('login')) return const [AutofillHints.username];
return const [];
}

static TextInputType _keyboard(SchoolSystemLoginField f) {
final key = f.key.toLowerCase();
if (f.type == 'url' || key.contains('url')) return TextInputType.url;
if (f.type == 'email' || key.contains('email') || key.contains('mail')) return TextInputType.emailAddress;
return TextInputType.text;
}

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
spacing: 16,
children: [
for (final field in controller.fields)
if (_isTotp(field))
TotpFieldPicker(
controller: controller.controllerFor(field.key),
field: field,
)
else
FTextField(
control: FTextFieldControl.managed(
final fields = controller.fields;
// One group, so the platform treats the boxes as a single credential rather
// than unrelated inputs.
return AutofillGroup(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
spacing: 16,
children: [
for (final (index, field) in fields.indexed)
if (_isTotp(field))
TotpFieldPicker(
controller: controller.controllerFor(field.key),
field: field,
)
else
FTextField(
control: FTextFieldControl.managed(
controller: controller.controllerFor(field.key),
),
label: Text(field.label),
hint: field.placeholder,
obscureText: field.type == 'password',
keyboardType: _keyboard(field),
textInputAction: index == fields.length - 1 ? TextInputAction.done : TextInputAction.next,
autofillHints: _autofillHints(field),
autocorrect: false,
),
label: Text(field.label),
hint: field.placeholder,
obscureText: field.type == 'password',
keyboardType: field.type == 'url'
? TextInputType.url
: TextInputType.text,
autocorrect: false,
),
],
],
),
);
}
}
Loading