Frontend first draft
This commit is contained in:
23
frontend/pweb/lib/widgets/password/hint/error.dart
Normal file
23
frontend/pweb/lib/widgets/password/hint/error.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/widgets/password/hint/widget.dart';
|
||||
|
||||
|
||||
class PasswordValidationErrorLabel extends StatelessWidget {
|
||||
final String labelText;
|
||||
const PasswordValidationErrorLabel({super.key, required this.labelText});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PasswordValidationOutput(
|
||||
children: [
|
||||
Text(
|
||||
labelText,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
)
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
18
frontend/pweb/lib/widgets/password/hint/full.dart
Normal file
18
frontend/pweb/lib/widgets/password/hint/full.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fancy_password_field/fancy_password_field.dart';
|
||||
|
||||
import 'package:pweb/widgets/password/hint/validation_result.dart';
|
||||
import 'package:pweb/widgets/password/hint/widget.dart';
|
||||
|
||||
|
||||
Widget expandedValidation(BuildContext context, Set<ValidationRule> rules, String value) {
|
||||
return PasswordValidationOutput(
|
||||
children: rules.map(
|
||||
(rule) => PasswordValidationResult(
|
||||
ruleName: rule.name,
|
||||
result: rule.validate(value),
|
||||
),
|
||||
).toList()
|
||||
);
|
||||
}
|
||||
25
frontend/pweb/lib/widgets/password/hint/short.dart
Normal file
25
frontend/pweb/lib/widgets/password/hint/short.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fancy_password_field/fancy_password_field.dart';
|
||||
|
||||
import 'package:pweb/widgets/password/hint/error.dart';
|
||||
import 'package:pweb/widgets/password/hint/widget.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
Widget shortValidation(BuildContext context, Set<ValidationRule> rules, String value) {
|
||||
if (value.isEmpty) return Container();
|
||||
final failedRules = rules.where((rule) => !rule.validate(value));
|
||||
return (failedRules.isNotEmpty)
|
||||
? PasswordValidationOutput(
|
||||
children: [
|
||||
PasswordValidationErrorLabel(
|
||||
labelText: AppLocalizations.of(context)!.passwordValidationError(
|
||||
rules.firstWhere((rule) => !rule.validate(value)).name
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Container();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class PasswordValidationResult extends StatelessWidget {
|
||||
final String ruleName;
|
||||
final bool result;
|
||||
|
||||
const PasswordValidationResult({
|
||||
super.key,
|
||||
required this.ruleName,
|
||||
required this.result
|
||||
});
|
||||
|
||||
Color _selectColor(BuildContext context, bool res) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return res ? scheme.secondary : scheme.error;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
result ? Icons.check : Icons.close,
|
||||
color: _selectColor(context, result),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
ruleName,
|
||||
style: TextStyle(color: _selectColor(context, result)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
23
frontend/pweb/lib/widgets/password/hint/widget.dart
Normal file
23
frontend/pweb/lib/widgets/password/hint/widget.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/widgets/vspacer.dart';
|
||||
|
||||
|
||||
class PasswordValidationOutput extends StatelessWidget {
|
||||
final List<Widget> children;
|
||||
|
||||
const PasswordValidationOutput({super.key, required this.children});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
VSpacer(multiplier: 0.25),
|
||||
ListView(
|
||||
shrinkWrap: true,
|
||||
children: children,
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user