Skip to content

Commit 8003a29

Browse files
committed
#339: added autofill
1 parent de53780 commit 8003a29

File tree

3 files changed

+49
-39
lines changed

3 files changed

+49
-39
lines changed

lib/screen/login/login_screen.dart

+42-38
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,50 @@ class LoginScreenState extends State<LoginScreen> {
2626
Widget build(BuildContext context) {
2727
return ProviderWidget<LoginViewModel>(
2828
create: () => getIt()..init(),
29-
consumerWithThemeAndLocalization: (context, viewModel, child, theme, localization) => BaseScreen(
30-
showHeader: false,
31-
children: [
32-
Container(height: 16),
33-
Text(
34-
'Login',
35-
style: theme.text.titleNormal,
36-
textAlign: TextAlign.center,
37-
),
38-
Container(height: 32),
39-
Text(
40-
'Just fill in some text. There is no validator for the login',
41-
style: theme.text.labelButtonSmall,
42-
),
43-
Container(height: 32),
44-
FlutterTemplateInputField(
45-
key: Keys.emailInput,
46-
enabled: !viewModel.isLoading,
47-
onChanged: viewModel.onEmailUpdated,
48-
hint: 'Email',
49-
),
50-
Container(height: 16),
51-
FlutterTemplateInputField(
52-
key: Keys.passwordInput,
53-
enabled: !viewModel.isLoading,
54-
onChanged: viewModel.onPasswordUpdated,
55-
hint: 'Password',
56-
),
57-
Container(height: 16),
58-
if (viewModel.isLoading) ...[
59-
const FlutterTemplateProgressIndicator.light(),
60-
] else ...[
61-
FlutterTemplateButton(
62-
key: Keys.loginButton,
63-
isEnabled: viewModel.isLoginEnabled,
64-
text: 'Login',
65-
onClick: viewModel.onLoginClicked,
29+
consumerWithThemeAndLocalization: (context, viewModel, child, theme, localization) => AutofillGroup(
30+
child: BaseScreen(
31+
showHeader: false,
32+
children: [
33+
Container(height: 16),
34+
Text(
35+
'Login',
36+
style: theme.text.titleNormal,
37+
textAlign: TextAlign.center,
6638
),
39+
Container(height: 32),
40+
Text(
41+
'Just fill in some text. There is no validator for the login',
42+
style: theme.text.labelButtonSmall,
43+
),
44+
Container(height: 32),
45+
FlutterTemplateInputField(
46+
key: Keys.emailInput,
47+
enabled: !viewModel.isLoading,
48+
onChanged: viewModel.onEmailUpdated,
49+
hint: 'Email',
50+
autoFillHints: const [AutofillHints.email],
51+
),
52+
Container(height: 16),
53+
FlutterTemplateInputField(
54+
key: Keys.passwordInput,
55+
enabled: !viewModel.isLoading,
56+
onChanged: viewModel.onPasswordUpdated,
57+
hint: 'Password',
58+
autoFillHints: const [AutofillHints.password],
59+
),
60+
Container(height: 16),
61+
if (viewModel.isLoading) ...[
62+
const FlutterTemplateProgressIndicator.light(),
63+
] else ...[
64+
FlutterTemplateButton(
65+
key: Keys.loginButton,
66+
isEnabled: viewModel.isLoginEnabled,
67+
text: 'Login',
68+
onClick: viewModel.onLoginClicked,
69+
),
70+
],
6771
],
68-
],
72+
),
6973
),
7074
);
7175
}

lib/viewmodel/login/login_viewmodel.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/services.dart';
12
import 'package:flutter_template/navigator/main_navigator.dart';
23
import 'package:flutter_template/navigator/onboarding_navigator.dart';
34
import 'package:flutter_template/repository/login/login_repository.dart';
@@ -42,6 +43,7 @@ class LoginViewModel with ChangeNotifierEx {
4243
try {
4344
_isLoading = true;
4445
await _loginRepo.login(email: _email, password: _password);
46+
TextInput.finishAutofillContext();
4547
return _onboardingNavigator.goToNextScreen();
4648
} catch (e, stack) {
4749
FlutterTemplateLogger.logError('Failed to login', error: e, stackTrace: stack);

lib/widget/general/styled/flutter_template_input_field.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import 'package:flutter_template/styles/theme_data.dart';
33
import 'package:flutter_template/widget/provider/data_provider_widget.dart';
44

55
class FlutterTemplateInputField extends StatelessWidget {
6-
final String hint;
76
final bool enabled;
7+
final String hint;
8+
final List<String>? autoFillHints;
89
final ValueChanged<String> onChanged;
910
final TextEditingController? controller;
1011

12+
1113
const FlutterTemplateInputField({
1214
required this.hint,
1315
required this.onChanged,
16+
this.autoFillHints,
1417
this.enabled = true,
1518
this.controller,
1619
super.key,
@@ -24,6 +27,7 @@ class FlutterTemplateInputField extends StatelessWidget {
2427
controller: controller,
2528
enabled: enabled,
2629
onChanged: onChanged,
30+
autofillHints: autoFillHints,
2731
decoration: InputDecoration(
2832
filled: true,
2933
hintText: hint,

0 commit comments

Comments
 (0)