mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
The api token toggle is now only visible when showing a custom server, since at the moment this is the only time when such an auth method makes sense (plus it keeps the rest of the UI cleaner). The different fields in the screen have been moved to individual files, to make the structure clearer.
44 lines
1.3 KiB
Dart
44 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:wger/l10n/generated/app_localizations.dart';
|
|
|
|
class UsernameField extends StatelessWidget {
|
|
final TextEditingController controller;
|
|
final Function(String?) onSaved;
|
|
|
|
const UsernameField({
|
|
required this.controller,
|
|
required this.onSaved,
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return TextFormField(
|
|
key: const Key('inputUsername'),
|
|
decoration: InputDecoration(
|
|
labelText: AppLocalizations.of(context).username,
|
|
errorMaxLines: 2,
|
|
prefixIcon: const Icon(Icons.account_circle),
|
|
),
|
|
autofillHints: const [AutofillHints.username],
|
|
controller: controller,
|
|
textInputAction: TextInputAction.next,
|
|
keyboardType: TextInputType.emailAddress,
|
|
validator: (value) {
|
|
if (value == null || value.isEmpty) {
|
|
return AppLocalizations.of(context).invalidUsername;
|
|
}
|
|
if (!RegExp(r'^[\w.@+-]+$').hasMatch(value)) {
|
|
return AppLocalizations.of(context).usernameValidChars;
|
|
}
|
|
return null;
|
|
},
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.deny(RegExp(r'\s\b|\b\s')),
|
|
],
|
|
onSaved: onSaved,
|
|
);
|
|
}
|
|
}
|