|
@@ -1,10 +1,10 @@
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter/services.dart';
|
|
|
import 'package:photos/theme/ente_theme.dart';
|
|
|
+import 'package:photos/ui/components/dialog_widget.dart';
|
|
|
import 'package:photos/utils/separators_util.dart';
|
|
|
|
|
|
-class TextInputWidget extends StatelessWidget {
|
|
|
- final TextEditingController textController;
|
|
|
+class TextInputWidget extends StatefulWidget {
|
|
|
final String? label;
|
|
|
final String? message;
|
|
|
final String? hintText;
|
|
@@ -13,8 +13,12 @@ class TextInputWidget extends StatelessWidget {
|
|
|
final Alignment? alignMessage;
|
|
|
final bool? autoFocus;
|
|
|
final int? maxLength;
|
|
|
+ final ValueNotifier? submitNotifier;
|
|
|
+ final bool alwaysShowSuccessState;
|
|
|
+ final bool showOnlyLoadingState;
|
|
|
+ final FutureVoidCallbackParamStr onSubmit;
|
|
|
const TextInputWidget({
|
|
|
- required this.textController,
|
|
|
+ required this.onSubmit,
|
|
|
this.label,
|
|
|
this.message,
|
|
|
this.hintText,
|
|
@@ -23,33 +27,57 @@ class TextInputWidget extends StatelessWidget {
|
|
|
this.alignMessage,
|
|
|
this.autoFocus,
|
|
|
this.maxLength,
|
|
|
+ this.submitNotifier,
|
|
|
+ this.alwaysShowSuccessState = false,
|
|
|
+ this.showOnlyLoadingState = false,
|
|
|
super.key,
|
|
|
});
|
|
|
|
|
|
+ @override
|
|
|
+ State<TextInputWidget> createState() => _TextInputWidgetState();
|
|
|
+}
|
|
|
+
|
|
|
+class _TextInputWidgetState extends State<TextInputWidget> {
|
|
|
+ final _textController = TextEditingController();
|
|
|
+
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ widget.submitNotifier?.addListener(() {
|
|
|
+ widget.onSubmit.call(_textController.text);
|
|
|
+ });
|
|
|
+ super.initState();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void dispose() {
|
|
|
+ widget.submitNotifier?.dispose();
|
|
|
+ super.dispose();
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
- if (initialValue != null) {
|
|
|
- textController.value = TextEditingValue(
|
|
|
- text: initialValue!,
|
|
|
- selection: TextSelection.collapsed(offset: initialValue!.length),
|
|
|
+ if (widget.initialValue != null) {
|
|
|
+ _textController.value = TextEditingValue(
|
|
|
+ text: widget.initialValue!,
|
|
|
+ selection: TextSelection.collapsed(offset: widget.initialValue!.length),
|
|
|
);
|
|
|
}
|
|
|
final colorScheme = getEnteColorScheme(context);
|
|
|
final textTheme = getEnteTextTheme(context);
|
|
|
var textInputChildren = <Widget>[];
|
|
|
- if (label != null) textInputChildren.add(Text(label!));
|
|
|
+ if (widget.label != null) textInputChildren.add(Text(widget.label!));
|
|
|
textInputChildren.add(
|
|
|
ClipRRect(
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
child: Material(
|
|
|
child: TextFormField(
|
|
|
- autofocus: autoFocus ?? false,
|
|
|
- controller: textController,
|
|
|
- inputFormatters: maxLength != null
|
|
|
+ autofocus: widget.autoFocus ?? false,
|
|
|
+ controller: _textController,
|
|
|
+ inputFormatters: widget.maxLength != null
|
|
|
? [LengthLimitingTextInputFormatter(50)]
|
|
|
: null,
|
|
|
decoration: InputDecoration(
|
|
|
- hintText: hintText,
|
|
|
+ hintText: widget.hintText,
|
|
|
hintStyle: textTheme.body.copyWith(color: colorScheme.textMuted),
|
|
|
filled: true,
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
@@ -75,25 +103,26 @@ class TextInputWidget extends StatelessWidget {
|
|
|
minHeight: 44,
|
|
|
minWidth: 44,
|
|
|
),
|
|
|
- prefixIcon: prefixIcon != null
|
|
|
+ prefixIcon: widget.prefixIcon != null
|
|
|
? Icon(
|
|
|
- prefixIcon,
|
|
|
+ widget.prefixIcon,
|
|
|
color: colorScheme.strokeMuted,
|
|
|
)
|
|
|
: null,
|
|
|
),
|
|
|
+ onEditingComplete: () {},
|
|
|
),
|
|
|
),
|
|
|
),
|
|
|
);
|
|
|
- if (message != null) {
|
|
|
+ if (widget.message != null) {
|
|
|
textInputChildren.add(
|
|
|
Padding(
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
|
child: Align(
|
|
|
- alignment: alignMessage ?? Alignment.centerLeft,
|
|
|
+ alignment: widget.alignMessage ?? Alignment.centerLeft,
|
|
|
child: Text(
|
|
|
- message!,
|
|
|
+ widget.message!,
|
|
|
style: textTheme.small.copyWith(color: colorScheme.textMuted),
|
|
|
),
|
|
|
),
|