From a9a8d9798b4cbb81be38e744db173ee7be4e51e4 Mon Sep 17 00:00:00 2001
From: vjrj <vjrj@comunes.org>
Date: Sun, 2 Apr 2023 13:53:14 +0200
Subject: [PATCH] Not allow Return in comment text field

---
 lib/ui/screens/pay_form.dart | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/lib/ui/screens/pay_form.dart b/lib/ui/screens/pay_form.dart
index 7c1cc19f..6640e42b 100644
--- a/lib/ui/screens/pay_form.dart
+++ b/lib/ui/screens/pay_form.dart
@@ -1,5 +1,6 @@
 import 'package:easy_localization/easy_localization.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
 import 'package:flutter_bloc/flutter_bloc.dart';
 
 import '../../data/models/payment_cubit.dart';
@@ -39,6 +40,7 @@ class _PayFormState extends State<PayForm> {
             const G1PayAmountField(),
             const SizedBox(height: 10.0),
             TextFormField(
+              inputFormatters: [NoNewLineTextInputFormatter()],
               controller: _commentController,
               onChanged: (String? value) {
                 final bool validate = _commentValidate();
@@ -60,7 +62,6 @@ class _PayFormState extends State<PayForm> {
                 }
                 return null;
               },
-              maxLines: null,
             ),
             const SizedBox(height: 10.0),
             ElevatedButton(
@@ -161,3 +162,18 @@ class _PayFormState extends State<PayForm> {
     );
   }
 }
+
+class NoNewLineTextInputFormatter extends TextInputFormatter {
+  @override
+  TextEditingValue formatEditUpdate(
+      TextEditingValue oldValue, TextEditingValue newValue) {
+    final String newText = newValue.text.replaceAll('\n', '');
+    return TextEditingValue(
+      text: newText,
+      selection: newValue.selection.copyWith(
+        baseOffset: newText.length,
+        extentOffset: newText.length,
+      ),
+    );
+  }
+}
-- 
GitLab