20 lines
763 B
Dart
20 lines
763 B
Dart
import 'package:flutter/services.dart';
|
|
|
|
/// Capitaliza automaticamente a primeira letra à medida que o utilizador
|
|
/// escreve — usado nos campos de nome (criança e conta) para não depender
|
|
/// só da sugestão do teclado (que o utilizador pode ignorar ou que pode
|
|
/// não existir em todos os teclados).
|
|
class CapitalizeFirstLetterFormatter extends TextInputFormatter {
|
|
@override
|
|
TextEditingValue formatEditUpdate(
|
|
TextEditingValue oldValue,
|
|
TextEditingValue newValue,
|
|
) {
|
|
final text = newValue.text;
|
|
if (text.isEmpty) return newValue;
|
|
final capitalized = text[0].toUpperCase() + text.substring(1);
|
|
if (capitalized == text) return newValue;
|
|
return newValue.copyWith(text: capitalized, selection: newValue.selection);
|
|
}
|
|
}
|