Browse Source

Added optional parameters textEditingController and textInputFormatter to showTextInputDialog()

ashilkn 2 years ago
parent
commit
d45af08120

+ 7 - 0
lib/ui/components/dialog_widget.dart

@@ -1,6 +1,7 @@
 import 'dart:math';
 
 import 'package:flutter/material.dart';
+import "package:flutter/services.dart";
 import 'package:photos/core/constants.dart';
 import "package:photos/generated/l10n.dart";
 import "package:photos/models/search/button_result.dart";
@@ -174,6 +175,8 @@ class TextInputDialog extends StatefulWidget {
   final TextCapitalization? textCapitalization;
   final bool alwaysShowSuccessState;
   final bool isPasswordInput;
+  final TextEditingController? textEditingController;
+  final List<TextInputFormatter>? textInputFormatter;
   const TextInputDialog({
     required this.title,
     this.body,
@@ -191,6 +194,8 @@ class TextInputDialog extends StatefulWidget {
     this.showOnlyLoadingState = false,
     this.alwaysShowSuccessState = false,
     this.isPasswordInput = false,
+    this.textEditingController,
+    this.textInputFormatter,
     super.key,
   });
 
@@ -251,6 +256,8 @@ class _TextInputDialogState extends State<TextInputDialog> {
                 textCapitalization: widget.textCapitalization,
                 alwaysShowSuccessState: widget.alwaysShowSuccessState,
                 isPasswordInput: widget.isPasswordInput,
+                textEditingController: widget.textEditingController,
+                textInputFormatter: widget.textInputFormatter,
               ),
             ),
             const SizedBox(height: 36),

+ 6 - 3
lib/ui/components/text_input_widget.dart

@@ -41,6 +41,7 @@ class TextInputWidget extends StatefulWidget {
   final VoidCallback? onCancel;
   final TextEditingController? textEditingController;
   final ValueNotifier? isEmptyNotifier;
+  final List<TextInputFormatter>? textInputFormatter;
   const TextInputWidget({
     this.onSubmit,
     this.onChange,
@@ -67,6 +68,7 @@ class TextInputWidget extends StatefulWidget {
     this.onCancel,
     this.textEditingController,
     this.isEmptyNotifier,
+    this.textInputFormatter,
     super.key,
   });
 
@@ -147,9 +149,10 @@ class _TextInputWidgetState extends State<TextInputWidget> {
             autofocus: widget.autoFocus ?? false,
             controller: _textController,
             focusNode: widget.focusNode,
-            inputFormatters: widget.maxLength != null
-                ? [LengthLimitingTextInputFormatter(50)]
-                : null,
+            inputFormatters: widget.textInputFormatter ??
+                (widget.maxLength != null
+                    ? [LengthLimitingTextInputFormatter(50)]
+                    : null),
             obscureText: _obscureTextNotifier.value,
             decoration: InputDecoration(
               hintText: widget.hintText,

+ 5 - 0
lib/utils/dialog_util.dart

@@ -3,6 +3,7 @@ import 'dart:math';
 import 'package:confetti/confetti.dart';
 import "package:dio/dio.dart";
 import 'package:flutter/material.dart';
+import "package:flutter/services.dart";
 import 'package:photos/core/constants.dart';
 import "package:photos/generated/l10n.dart";
 import "package:photos/models/search/button_result.dart";
@@ -303,6 +304,8 @@ Future<dynamic> showTextInputDialog(
   TextCapitalization textCapitalization = TextCapitalization.none,
   bool alwaysShowSuccessState = false,
   bool isPasswordInput = false,
+  TextEditingController? textEditingController,
+  List<TextInputFormatter>? textInputFormatter,
 }) {
   return showDialog(
     barrierColor: backdropFaintDark,
@@ -330,6 +333,8 @@ Future<dynamic> showTextInputDialog(
             textCapitalization: textCapitalization,
             alwaysShowSuccessState: alwaysShowSuccessState,
             isPasswordInput: isPasswordInput,
+            textEditingController: textEditingController,
+            textInputFormatter: textInputFormatter,
           ),
         ),
       );