Skip to content
Snippets Groups Projects
Commit a9a8d979 authored by vjrj's avatar vjrj
Browse files

Not allow Return in comment text field

parent 0d84d8db
No related branches found
No related tags found
No related merge requests found
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,
),
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment