Skip to content

Commit

Permalink
#339: added autofill
Browse files Browse the repository at this point in the history
  • Loading branch information
jorre127 committed Oct 16, 2024
1 parent de53780 commit 8003a29
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 39 deletions.
80 changes: 42 additions & 38 deletions lib/screen/login/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,50 @@ class LoginScreenState extends State<LoginScreen> {
Widget build(BuildContext context) {
return ProviderWidget<LoginViewModel>(
create: () => getIt()..init(),
consumerWithThemeAndLocalization: (context, viewModel, child, theme, localization) => BaseScreen(
showHeader: false,
children: [
Container(height: 16),
Text(
'Login',
style: theme.text.titleNormal,
textAlign: TextAlign.center,
),
Container(height: 32),
Text(
'Just fill in some text. There is no validator for the login',
style: theme.text.labelButtonSmall,
),
Container(height: 32),
FlutterTemplateInputField(
key: Keys.emailInput,
enabled: !viewModel.isLoading,
onChanged: viewModel.onEmailUpdated,
hint: 'Email',
),
Container(height: 16),
FlutterTemplateInputField(
key: Keys.passwordInput,
enabled: !viewModel.isLoading,
onChanged: viewModel.onPasswordUpdated,
hint: 'Password',
),
Container(height: 16),
if (viewModel.isLoading) ...[
const FlutterTemplateProgressIndicator.light(),
] else ...[
FlutterTemplateButton(
key: Keys.loginButton,
isEnabled: viewModel.isLoginEnabled,
text: 'Login',
onClick: viewModel.onLoginClicked,
consumerWithThemeAndLocalization: (context, viewModel, child, theme, localization) => AutofillGroup(
child: BaseScreen(
showHeader: false,
children: [
Container(height: 16),
Text(
'Login',
style: theme.text.titleNormal,
textAlign: TextAlign.center,
),
Container(height: 32),
Text(
'Just fill in some text. There is no validator for the login',
style: theme.text.labelButtonSmall,
),
Container(height: 32),
FlutterTemplateInputField(
key: Keys.emailInput,
enabled: !viewModel.isLoading,
onChanged: viewModel.onEmailUpdated,
hint: 'Email',
autoFillHints: const [AutofillHints.email],
),
Container(height: 16),
FlutterTemplateInputField(
key: Keys.passwordInput,
enabled: !viewModel.isLoading,
onChanged: viewModel.onPasswordUpdated,
hint: 'Password',
autoFillHints: const [AutofillHints.password],
),
Container(height: 16),
if (viewModel.isLoading) ...[
const FlutterTemplateProgressIndicator.light(),
] else ...[
FlutterTemplateButton(
key: Keys.loginButton,
isEnabled: viewModel.isLoginEnabled,
text: 'Login',
onClick: viewModel.onLoginClicked,
),
],
],
],
),
),
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/viewmodel/login/login_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/services.dart';
import 'package:flutter_template/navigator/main_navigator.dart';
import 'package:flutter_template/navigator/onboarding_navigator.dart';
import 'package:flutter_template/repository/login/login_repository.dart';
Expand Down Expand Up @@ -42,6 +43,7 @@ class LoginViewModel with ChangeNotifierEx {
try {
_isLoading = true;
await _loginRepo.login(email: _email, password: _password);
TextInput.finishAutofillContext();
return _onboardingNavigator.goToNextScreen();
} catch (e, stack) {
FlutterTemplateLogger.logError('Failed to login', error: e, stackTrace: stack);
Expand Down
6 changes: 5 additions & 1 deletion lib/widget/general/styled/flutter_template_input_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import 'package:flutter_template/styles/theme_data.dart';
import 'package:flutter_template/widget/provider/data_provider_widget.dart';

class FlutterTemplateInputField extends StatelessWidget {
final String hint;
final bool enabled;
final String hint;
final List<String>? autoFillHints;
final ValueChanged<String> onChanged;
final TextEditingController? controller;


const FlutterTemplateInputField({
required this.hint,
required this.onChanged,
this.autoFillHints,
this.enabled = true,
this.controller,
super.key,
Expand All @@ -24,6 +27,7 @@ class FlutterTemplateInputField extends StatelessWidget {
controller: controller,
enabled: enabled,
onChanged: onChanged,
autofillHints: autoFillHints,
decoration: InputDecoration(
filled: true,
hintText: hint,
Expand Down

0 comments on commit 8003a29

Please sign in to comment.