Skip to content

Instantly share code, notes, and snippets.

@saitbnzl
Created August 29, 2019 11:16
Show Gist options
  • Save saitbnzl/601fdd2c61c6bfe3f062c0ef9a67b38e to your computer and use it in GitHub Desktop.
Save saitbnzl/601fdd2c61c6bfe3f062c0ef9a67b38e to your computer and use it in GitHub Desktop.
Simple input capitalizer in Dart. You can use it inside InputFormatters in Flutter.
import 'package:flutter/services.dart';
import 'package:paynet/common/utils/index.dart';
class InputCapitalizer extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) {
int selectionIndex = newValue.selection.end;
return TextEditingValue(
text: newValue.text.toUpperCase(),
selection: TextSelection.collapsed(offset: selectionIndex),
);
}
}
@saitbnzl
Copy link
Author

saitbnzl commented Aug 29, 2019

Important notice about toUpperCaseMethod:

This function uses the language independent Unicode mapping and thus only works in some languages.

For example, there is a package for Turkish which solves these character issues of toUpperCaseMethod etc.: https://github.com/ahmetaa/turkish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment