Merge pull request 'Maximale Input in Textfelder gefixtx' (#176) from hotifx/fix-input-length into development
Reviewed-on: #176 Reviewed-by: Mathis Kirchner <mathis.kirchner.mk@gmail.com>
This commit was merged in pull request #176.
This commit is contained in:
@@ -84,6 +84,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
CustomSearchBar(
|
||||
maxLength: Constants.MAX_PLAYER_NAME_LENGTH,
|
||||
controller: _searchBarController,
|
||||
constraints: const BoxConstraints(maxHeight: 45, minHeight: 45),
|
||||
hintText: loc.search_for_players,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:game_tracker/core/constants.dart';
|
||||
import 'package:game_tracker/core/custom_theme.dart';
|
||||
|
||||
class CustomSearchBar extends StatelessWidget {
|
||||
@@ -22,6 +21,7 @@ class CustomSearchBar extends StatelessWidget {
|
||||
this.onTrailingButtonPressed,
|
||||
this.onChanged,
|
||||
this.constraints,
|
||||
this.maxLength,
|
||||
});
|
||||
|
||||
/// The controller for the search bar's text input.
|
||||
@@ -48,16 +48,20 @@ class CustomSearchBar extends StatelessWidget {
|
||||
/// The constraints for the search bar.
|
||||
final BoxConstraints? constraints;
|
||||
|
||||
/// Optional parameter for maximum length of the input text.
|
||||
final int? maxLength;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
/// Enforce maximum length on the input text
|
||||
const maxLength = Constants.MAX_PLAYER_NAME_LENGTH;
|
||||
if (controller.text.length > maxLength) {
|
||||
if (maxLength != null) {
|
||||
if (controller.text.length > maxLength!) {
|
||||
controller.text = controller.text.substring(0, maxLength);
|
||||
controller.selection = TextSelection.fromPosition(
|
||||
TextPosition(offset: controller.text.length),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return SearchBar(
|
||||
controller: controller,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:game_tracker/core/custom_theme.dart';
|
||||
|
||||
class TextInputField extends StatelessWidget {
|
||||
@@ -33,11 +34,14 @@ class TextInputField extends StatelessWidget {
|
||||
controller: controller,
|
||||
onChanged: onChanged,
|
||||
maxLength: maxLength,
|
||||
maxLengthEnforcement: MaxLengthEnforcement.truncateAfterCompositionEnds,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: CustomTheme.boxColor,
|
||||
hintText: hintText,
|
||||
hintStyle: const TextStyle(fontSize: 18),
|
||||
// Hides the character counter
|
||||
counterText: '',
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||
borderSide: BorderSide(color: CustomTheme.boxBorder),
|
||||
|
||||
Reference in New Issue
Block a user