π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][locker] Remove legacy form input components
aman-piloteedc2422ad3d
diff --git a/mobile/apps/locker/lib/ui/components/capsule_form_field.dart b/mobile/apps/locker/lib/ui/components/capsule_form_field.dartdeleted file mode 100644index c0d91dab91..0000000000--- a/mobile/apps/locker/lib/ui/components/capsule_form_field.dart+++ /dev/null@@ -1,366 +0,0 @@-import 'package:ente_components/ente_components.dart';-import 'package:flutter/material.dart';-import 'package:flutter/services.dart';--class CapsuleFormField extends StatefulWidget {- const CapsuleFormField({- super.key,- required this.controller,- required this.labelText,- this.hintText,- this.focusNode,- this.validator,- this.trailing,- this.autofocus = false,- this.obscureText = false,- this.enabled = true,- this.readOnly = false,- this.maxLines = 1,- this.minLines,- this.keyboardType,- this.textCapitalization = TextCapitalization.none,- this.textInputAction,- this.inputFormatters,- this.onChanged,- this.onEditingComplete,- this.onSubmitted,- this.lineHeight,- this.contentPadding = const EdgeInsets.symmetric(- horizontal: 24,- vertical: 18,- ),- });-- final TextEditingController controller;- final FocusNode? focusNode;- final String labelText;- final String? hintText;- final String? Function(String?)? validator;- final Widget? trailing;- final bool autofocus;- final bool obscureText;- final bool enabled;- final bool readOnly;- final int? maxLines;- final int? minLines;- final TextInputType? keyboardType;- final TextCapitalization textCapitalization;- final TextInputAction? textInputAction;- final List<TextInputFormatter>? inputFormatters;- final ValueChanged<String>? onChanged;- final VoidCallback? onEditingComplete;- final ValueChanged<String>? onSubmitted;- final double? lineHeight;- final EdgeInsets contentPadding;-- @override- State<CapsuleFormField> createState() => _CapsuleFormFieldState();-}--class _CapsuleFormFieldState extends State<CapsuleFormField> {- final GlobalKey<FormFieldState<String>> _fieldKey =- GlobalKey<FormFieldState<String>>();- FocusNode? _internalFocusNode;-- FocusNode get _focusNode => widget.focusNode ?? _internalFocusNode!;-- @override- void initState() {- super.initState();- _ensureFocusNode();- widget.controller.addListener(_handleControllerChanged);- _focusNode.addListener(_handleFocusChanged);- }-- void _ensureFocusNode() {- if (widget.focusNode == null && _internalFocusNode == null) {- _internalFocusNode = FocusNode();- }- }-- @override- void didUpdateWidget(CapsuleFormField oldWidget) {- super.didUpdateWidget(oldWidget);- if (oldWidget.focusNode != widget.focusNode) {- oldWidget.focusNode?.removeListener(_handleFocusChanged);- _internalFocusNode?.removeListener(_handleFocusChanged);- if (oldWidget.focusNode == null) {- _internalFocusNode?.dispose();- _internalFocusNode = null;- }- _ensureFocusNode();- _focusNode.addListener(_handleFocusChanged);- }-- if (oldWidget.controller != widget.controller) {- oldWidget.controller.removeListener(_handleControllerChanged);- widget.controller.addListener(_handleControllerChanged);- _fieldKey.currentState?.didChange(widget.controller.text);- }- }-- @override- void dispose() {- widget.controller.removeListener(_handleControllerChanged);- _focusNode.removeListener(_handleFocusChanged);- _internalFocusNode?.dispose();- super.dispose();- }-- void _handleControllerChanged() {- _fieldKey.currentState?.didChange(widget.controller.text);- if (mounted) {- setState(() {});- }- }-- void _handleFocusChanged() {- if (mounted) {- setState(() {});- }- }-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;-- final isEnabled = widget.enabled && !widget.readOnly;- _focusNode.canRequestFocus = isEnabled;- final hasFocus = _focusNode.hasFocus && isEnabled;- final bool isMultiline =- (widget.maxLines ?? 1) > 1 || (widget.minLines ?? 1) > 1;- final int? effectiveMaxLines = widget.obscureText ? 1 : widget.maxLines;- final int effectiveMinLines = widget.obscureText- ? 1- : (widget.minLines ?? (isMultiline ? (widget.maxLines ?? 3) : 1));- final textInputType =- widget.keyboardType ??- (isMultiline ? TextInputType.multiline : TextInputType.text);-- final backgroundColor = !widget.enabled- ? colors.fillDarker- : hasFocus- ? colors.primaryLight- : colors.fillDark;-- final textLineHeight = widget.lineHeight ?? (isMultiline ? 1.5 : 1.25);- final textColor = widget.enabled ? colors.textBase : colors.textLighter;-- return FormField<String>(- key: _fieldKey,- autovalidateMode: AutovalidateMode.disabled,- validator: (value) => widget.validator?.call(widget.controller.text),- builder: (field) {- final hasError = field.hasError;- final errorText = field.errorText;-- return Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- if (widget.labelText.isNotEmpty) ...[- Text(widget.labelText, style: TextStyles.body),- const SizedBox(height: 8),- ],- AnimatedContainer(- duration: const Duration(milliseconds: 220),- curve: Curves.easeOutCubic,- decoration: BoxDecoration(- color: backgroundColor,- borderRadius: BorderRadius.circular(24),- ),- child: Padding(- padding: widget.contentPadding,- child: Row(- crossAxisAlignment: (widget.maxLines ?? 1) > 1- ? CrossAxisAlignment.start- : CrossAxisAlignment.center,- children: [- Expanded(- child: TextField(- controller: widget.controller,- focusNode: _focusNode,- readOnly: widget.readOnly,- enabled: widget.enabled,- autofocus: widget.autofocus,- obscureText: widget.obscureText,- obscuringCharacter: 'β’',- enableSuggestions: !widget.obscureText,- autocorrect: !widget.obscureText,- keyboardType: textInputType,- textCapitalization: widget.textCapitalization,- textInputAction: widget.textInputAction,- inputFormatters: widget.inputFormatters,- maxLines: effectiveMaxLines,- minLines: effectiveMinLines,- onChanged: (value) {- field.didChange(value);- widget.onChanged?.call(value);- },- onEditingComplete: widget.onEditingComplete,- onSubmitted: widget.onSubmitted,- cursorColor: colors.textBase,- style: TextStyles.body.copyWith(- height: textLineHeight,- color: textColor,- ),- textAlignVertical: isMultiline- ? TextAlignVertical.top- : TextAlignVertical.center,- decoration: InputDecoration.collapsed(- hintText: widget.hintText,- hintStyle: TextStyles.body.copyWith(- color: colors.textLighter,- height: textLineHeight,- ),- ),- ),- ),- if (widget.trailing != null) ...[- const SizedBox(width: 8),- widget.trailing!,- ],- ],- ),- ),- ),- if (hasError && errorText != null) ...[- const SizedBox(height: 6),- Text(- errorText,- style: TextStyles.mini.copyWith(color: colors.warning),- ),- ],- ],- );- },- );- }-}--class CapsuleDisplayField extends StatefulWidget {- const CapsuleDisplayField({- super.key,- required this.labelText,- required this.value,- this.isSecret = false,- this.maxLines,- this.lineHeight,- this.onCopy,- this.contentPadding = const EdgeInsets.symmetric(- horizontal: 24,- vertical: 18,- ),- });-- final String labelText;- final String value;- final bool isSecret;- final int? maxLines;- final double? lineHeight;- final VoidCallback? onCopy;- final EdgeInsets contentPadding;-- @override- State<CapsuleDisplayField> createState() => _CapsuleDisplayFieldState();-}--class _CapsuleDisplayFieldState extends State<CapsuleDisplayField> {- bool _isVisible = false;-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;- final displayValue = (widget.isSecret && !_isVisible)- ? 'β’' * widget.value.length- : widget.value;- final textLineHeight =- widget.lineHeight ?? ((widget.maxLines ?? 1) > 1 ? 1.5 : 1.3);-- return Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- if (widget.labelText.isNotEmpty) ...[- Text(widget.labelText, style: TextStyles.body),- const SizedBox(height: 8),- ],- Container(- decoration: BoxDecoration(- color: colors.fillDark,- borderRadius: BorderRadius.circular(24),- ),- child: Padding(- padding: widget.contentPadding,- child: Row(- crossAxisAlignment: (widget.maxLines ?? 1) > 1- ? CrossAxisAlignment.start- : CrossAxisAlignment.center,- children: [- Expanded(- child: (widget.isSecret && !_isVisible)- ? Text(- displayValue,- style: TextStyles.body.copyWith(- height: textLineHeight,- ),- maxLines: 1,- overflow: TextOverflow.clip,- )- : SelectableText(- displayValue,- style: TextStyles.body.copyWith(- height: textLineHeight,- ),- maxLines: widget.maxLines,- ),- ),- if (widget.isSecret) ...[- const SizedBox(width: 12),- GestureDetector(- onTap: () {- setState(() {- _isVisible = !_isVisible;- });- },- child: Container(- padding: const EdgeInsets.all(8),- decoration: BoxDecoration(- color: colors.fillBase.withValues(alpha: 0.1),- borderRadius: BorderRadius.circular(12),- ),- child: Icon(- _isVisible ? Icons.visibility : Icons.visibility_off,- size: 16,- semanticLabel: _isVisible- ? 'hide_password'- : 'show_password',- color: colors.textLight,- ),- ),- ),- ],- if (widget.onCopy != null) ...[- const SizedBox(width: 12),- GestureDetector(- onTap: widget.onCopy,- child: Container(- padding: const EdgeInsets.all(8),- decoration: BoxDecoration(- color: colors.fillBase.withValues(alpha: 0.1),- borderRadius: BorderRadius.circular(12),- ),- child: Icon(- Icons.copy,- size: 16,- color: colors.textLight,- ),- ),- ),- ],- ],- ),- ),- ),- ],- );- }-}diff --git a/mobile/apps/locker/lib/ui/components/form_text_input_widget.dart b/mobile/apps/locker/lib/ui/components/form_text_input_widget.dartdeleted file mode 100644index e9de134b21..0000000000--- a/mobile/apps/locker/lib/ui/components/form_text_input_widget.dart+++ /dev/null@@ -1,213 +0,0 @@-import 'package:ente_components/ente_components.dart';-import 'package:ente_ui/components/text_input_widget.dart';-import 'package:flutter/material.dart';-import 'package:flutter/services.dart';--/// A form-compatible wrapper that uses Ente UI TextInputWidget when possible,-/// or falls back to custom implementation for advanced features-class FormTextInputWidget extends StatefulWidget {- final TextEditingController controller;- final String labelText;- final String? hintText;- final String? Function(String?)? validator;- final bool obscureText;- final Widget? suffixIcon;- final int? maxLines;- final TextCapitalization textCapitalization;- final TextInputType? keyboardType;- final bool enabled;- final bool autofocus;- final int? maxLength;- final bool showValidationErrors;- final bool shouldUseTextInputWidget;-- const FormTextInputWidget({- super.key,- required this.controller,- required this.labelText,- this.hintText,- this.validator,- this.obscureText = false,- this.suffixIcon,- this.maxLines = 1,- this.textCapitalization = TextCapitalization.none,- this.keyboardType,- this.enabled = true,- this.autofocus = false,- this.maxLength,- this.showValidationErrors = false,- this.shouldUseTextInputWidget = true,- });-- @override- State<FormTextInputWidget> createState() => _FormTextInputWidgetState();-}--class _FormTextInputWidgetState extends State<FormTextInputWidget> {- final GlobalKey<FormFieldState> _formFieldKey = GlobalKey<FormFieldState>();- String? _errorText;-- @override- void initState() {- super.initState();- widget.controller.addListener(_onTextChanged);- }-- @override- void dispose() {- widget.controller.removeListener(_onTextChanged);- super.dispose();- }-- void _onTextChanged() {- if (_errorText != null) {- setState(() {- _errorText = null;- });- }- // Only validate if we should show validation errors- if (widget.showValidationErrors) {- _formFieldKey.currentState?.validate();- }- }-- // Check if we can use the UI package's TextInputWidget- bool get _canUseTextInputWidget {- return widget.suffixIcon == null &&- (widget.maxLines ?? 1) == 1 &&- widget.enabled &&- widget.shouldUseTextInputWidget;- }-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;-- return Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- if (_canUseTextInputWidget) ...[- // Use the UI package's TextInputWidget for simple cases- TextInputWidget(- label: widget.labelText,- hintText: widget.hintText,- initialValue: widget.controller.text,- isPasswordInput: widget.obscureText,- textCapitalization: widget.textCapitalization,- autoFocus: widget.autofocus,- maxLength: widget.maxLength,- shouldSurfaceExecutionStates: false,- onChange: (value) {- if (widget.controller.text != value) {- widget.controller.text = value;- }- },- ),- ] else ...[- // Custom implementation for advanced features- if (widget.labelText.isNotEmpty) ...[- Text(widget.labelText, style: TextStyles.body),- const SizedBox(height: 8),- ],- ClipRRect(- borderRadius: const BorderRadius.all(Radius.circular(8)),- child: Material(- color: Colors.transparent,- child: TextFormField(- controller: widget.controller,- validator: (value) => null, // Handled separately- obscureText: widget.obscureText,- maxLines: widget.obscureText ? 1 : widget.maxLines,- textCapitalization: widget.textCapitalization,- keyboardType: widget.keyboardType,- enabled: widget.enabled,- autofocus: widget.autofocus,- inputFormatters: widget.maxLength != null- ? [LengthLimitingTextInputFormatter(widget.maxLength!)]- : null,- style: TextStyles.body,- decoration: InputDecoration(- hintText: widget.hintText,- hintStyle: TextStyles.body.copyWith(- color: colors.textLighter,- ),- filled: true,- fillColor: colors.fillDark,- contentPadding: const EdgeInsets.fromLTRB(12, 12, 12, 12),- border: const UnderlineInputBorder(- borderSide: BorderSide.none,- ),- enabledBorder: OutlineInputBorder(- borderSide: BorderSide.none,- borderRadius: BorderRadius.circular(8),- ),- focusedBorder: OutlineInputBorder(- borderSide: BorderSide(color: colors.strokeFaint, width: 2),- borderRadius: BorderRadius.circular(8),- ),- errorBorder: OutlineInputBorder(- borderSide: BorderSide(color: colors.warning, width: 1),- borderRadius: BorderRadius.circular(8),- ),- focusedErrorBorder: OutlineInputBorder(- borderSide: BorderSide(color: colors.warning, width: 2),- borderRadius: BorderRadius.circular(8),- ),- suffixIcon: widget.suffixIcon != null- ? Padding(- padding: const EdgeInsets.symmetric(horizontal: 12),- child: widget.suffixIcon,- )- : null,- suffixIconConstraints: const BoxConstraints(- maxHeight: 24,- maxWidth: 48,- minHeight: 24,- minWidth: 48,- ),- errorStyle: const TextStyle(fontSize: 0, height: 0),- ),- ),- ),- ),- ],-- // Custom validation error display (for both cases)- if (_errorText != null && widget.showValidationErrors) ...[- const SizedBox(height: 4),- Padding(- padding: const EdgeInsets.symmetric(horizontal: 8),- child: Text(- _errorText!,- style: TextStyles.mini.copyWith(color: colors.warning),- ),- ),- ],-- // Invisible FormField for validation integration- SizedBox(- height: 0,- child: FormField<String>(- key: _formFieldKey,- validator: (value) {- final error = widget.validator?.call(widget.controller.text);- if (mounted && widget.showValidationErrors) {- WidgetsBinding.instance.addPostFrameCallback((_) {- if (mounted) {- setState(() {- _errorText = error;- });- }- });- }- return error;- },- builder: (FormFieldState<String> field) {- return const SizedBox.shrink();- },- ),- ),- ],- );- }-}