Implemented constants
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:game_tracker/core/constants.dart';
|
||||
import 'package:game_tracker/core/custom_theme.dart';
|
||||
|
||||
class CustomSearchBar extends StatelessWidget {
|
||||
@@ -49,6 +50,15 @@ class CustomSearchBar extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
/// Enforce maximum length on the input text
|
||||
const maxLength = Constants.MAX_PLAYER_NAME_LENGTH;
|
||||
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,
|
||||
constraints:
|
||||
|
||||
@@ -6,11 +6,13 @@ class TextInputField extends StatelessWidget {
|
||||
/// - [controller]: The controller for the text input field.
|
||||
/// - [onChanged]: The callback invoked when the text in the field changes.
|
||||
/// - [hintText]: The hint text displayed in the text input field when it is empty
|
||||
/// - [maxLength]: The maximum length of the input text.
|
||||
const TextInputField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.hintText,
|
||||
this.onChanged,
|
||||
this.maxLength,
|
||||
});
|
||||
|
||||
/// The controller for the text input field.
|
||||
@@ -22,11 +24,15 @@ class TextInputField extends StatelessWidget {
|
||||
/// The hint text displayed in the text input field when it is empty.
|
||||
final String hintText;
|
||||
|
||||
/// The maximum length of the input text.
|
||||
final int? maxLength;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextField(
|
||||
controller: controller,
|
||||
onChanged: onChanged,
|
||||
maxLength: maxLength,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: CustomTheme.boxColor,
|
||||
|
||||
Reference in New Issue
Block a user