diff --git a/lib/presentation/views/main_menu/group_view/create_group_view.dart b/lib/presentation/views/main_menu/group_view/create_group_view.dart index 719b47d..da7eb1d 100644 --- a/lib/presentation/views/main_menu/group_view/create_group_view.dart +++ b/lib/presentation/views/main_menu/group_view/create_group_view.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:game_tracker/core/constants.dart'; import 'package:game_tracker/core/custom_theme.dart'; import 'package:game_tracker/core/enums.dart'; import 'package:game_tracker/data/db/database.dart'; @@ -58,6 +59,7 @@ class _CreateGroupViewState extends State { child: TextInputField( controller: _groupNameController, hintText: loc.group_name, + maxLength: Constants.MAX_GROUP_NAME_LENGTH, ), ), Expanded( diff --git a/lib/presentation/views/main_menu/match_view/create_match/create_match_view.dart b/lib/presentation/views/main_menu/match_view/create_match/create_match_view.dart index 694a82d..ea9cfd5 100644 --- a/lib/presentation/views/main_menu/match_view/create_match/create_match_view.dart +++ b/lib/presentation/views/main_menu/match_view/create_match/create_match_view.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:game_tracker/core/adaptive_page_route.dart'; +import 'package:game_tracker/core/constants.dart'; import 'package:game_tracker/core/custom_theme.dart'; import 'package:game_tracker/core/enums.dart'; import 'package:game_tracker/data/db/database.dart'; @@ -136,6 +137,7 @@ class _CreateMatchViewState extends State { child: TextInputField( controller: _matchNameController, hintText: hintText ?? '', + maxLength: Constants.MAX_MATCH_NAME_LENGTH, ), ), ChooseTile( diff --git a/lib/presentation/widgets/text_input/custom_search_bar.dart b/lib/presentation/widgets/text_input/custom_search_bar.dart index 1b453da..76bb6e5 100644 --- a/lib/presentation/widgets/text_input/custom_search_bar.dart +++ b/lib/presentation/widgets/text_input/custom_search_bar.dart @@ -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: diff --git a/lib/presentation/widgets/text_input/text_input_field.dart b/lib/presentation/widgets/text_input/text_input_field.dart index 7d11767..37f9ce4 100644 --- a/lib/presentation/widgets/text_input/text_input_field.dart +++ b/lib/presentation/widgets/text_input/text_input_field.dart @@ -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, diff --git a/pubspec.yaml b/pubspec.yaml index e9fd894..9f957c2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: game_tracker description: "Game Tracking App for Card Games" publish_to: 'none' -version: 0.0.7+212 +version: 0.0.7+213 environment: sdk: ^3.8.1