support autofill in accounts_page

This commit is contained in:
boa-z
2024-11-02 23:31:12 +08:00
parent 28913adc86
commit 77ef0fb404

View File

@@ -173,84 +173,88 @@ class _LoginPageState extends State<_LoginPage> {
child: Container( child: Container(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
constraints: const BoxConstraints(maxWidth: 400), constraints: const BoxConstraints(maxWidth: 400),
child: Column( child: AutofillGroup(
mainAxisSize: MainAxisSize.min, child: Column(
children: [ mainAxisSize: MainAxisSize.min,
Text("Login".tl, style: const TextStyle(fontSize: 24)), children: [
const SizedBox(height: 32), Text("Login".tl, style: const TextStyle(fontSize: 24)),
if (widget.config.cookieFields == null) const SizedBox(height: 32),
TextField( if (widget.config.cookieFields == null)
decoration: InputDecoration( TextField(
labelText: "Username".tl, decoration: InputDecoration(
border: const OutlineInputBorder(), labelText: "Username".tl,
), border: const OutlineInputBorder(),
enabled: widget.config.login != null, ),
onChanged: (s) { enabled: widget.config.login != null,
username = s; onChanged: (s) {
}, username = s;
).paddingBottom(16), },
if (widget.config.cookieFields == null) autofillHints: const [AutofillHints.username],
TextField( ).paddingBottom(16),
decoration: InputDecoration( if (widget.config.cookieFields == null)
labelText: "Password".tl, TextField(
border: const OutlineInputBorder(), decoration: InputDecoration(
), labelText: "Password".tl,
obscureText: true, border: const OutlineInputBorder(),
enabled: widget.config.login != null, ),
onChanged: (s) { obscureText: true,
password = s; enabled: widget.config.login != null,
}, onChanged: (s) {
onSubmitted: (s) => login(), password = s;
).paddingBottom(16), },
for (var field in widget.config.cookieFields ?? <String>[]) onSubmitted: (s) => login(),
TextField( autofillHints: const [AutofillHints.password],
decoration: InputDecoration( ).paddingBottom(16),
labelText: field, for (var field in widget.config.cookieFields ?? <String>[])
border: const OutlineInputBorder(), TextField(
), decoration: InputDecoration(
obscureText: true, labelText: field,
enabled: widget.config.validateCookies != null, border: const OutlineInputBorder(),
onChanged: (s) { ),
_cookies[field] = s; obscureText: true,
}, enabled: widget.config.validateCookies != null,
).paddingBottom(16), onChanged: (s) {
if (widget.config.login == null && _cookies[field] = s;
widget.config.cookieFields == null) },
Row( ).paddingBottom(16),
mainAxisSize: MainAxisSize.min, if (widget.config.login == null &&
children: [ widget.config.cookieFields == null)
const Icon(Icons.error_outline), Row(
const SizedBox(width: 8),
Text("Login with password is disabled".tl),
],
)
else
Button.filled(
isLoading: loading,
onPressed: login,
child: Text("Continue".tl),
),
const SizedBox(height: 24),
if (widget.config.loginWebsite != null)
TextButton(
onPressed: loginWithWebview,
child: Text("Login with webview".tl),
),
const SizedBox(height: 8),
if (widget.config.registerWebsite != null)
TextButton(
onPressed: () =>
launchUrlString(widget.config.registerWebsite!),
child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
const Icon(Icons.link), const Icon(Icons.error_outline),
const SizedBox(width: 8), const SizedBox(width: 8),
Text("Create Account".tl), Text("Login with password is disabled".tl),
], ],
)
else
Button.filled(
isLoading: loading,
onPressed: login,
child: Text("Continue".tl),
), ),
), const SizedBox(height: 24),
], if (widget.config.loginWebsite != null)
TextButton(
onPressed: loginWithWebview,
child: Text("Login with webview".tl),
),
const SizedBox(height: 8),
if (widget.config.registerWebsite != null)
TextButton(
onPressed: () =>
launchUrlString(widget.config.registerWebsite!),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.link),
const SizedBox(width: 8),
Text("Create Account".tl),
],
),
),
],
),
), ),
), ),
), ),