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

Simplify comment field to improve usability

parent 7681e4bc
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/app_cubit.dart';
......@@ -69,12 +68,10 @@ class _PayFormState extends State<PayForm> {
Expanded(
child: TextFormField(
key: _formCommentKey,
inputFormatters: <TextInputFormatter>[
NoNewLineTextInputFormatter()
],
controller: _commentController,
onChanged: (String? value) {
context.read<PaymentCubit>().setComment(value ?? '');
final String newText = (value ?? '').replaceAll('\n', '');
context.read<PaymentCubit>().setComment(newText);
},
decoration: InputDecoration(
labelText: tr('g1_form_pay_desc'),
......@@ -226,18 +223,3 @@ class _PayFormState extends State<PayForm> {
class RetryException implements Exception {
RetryException();
}
class NoNewLineTextInputFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) {
final int cursorPosition = newValue.selection.baseOffset;
final String newText = newValue.text.replaceAll('\n', '');
final TextSelection newSelection =
TextSelection.collapsed(offset: cursorPosition);
return TextEditingValue(
text: newText,
selection: newSelection,
);
}
}
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