Refactored components

This commit is contained in:
2026-01-07 14:05:19 +01:00
parent 6e45e9435b
commit 21c74b74bc
20 changed files with 429 additions and 159 deletions

View File

@@ -1,10 +1,11 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
/// A tile widget that allows users to choose an option by tapping on it.
/// - [title]: The title text displayed on the tile.
/// - [trailingText]: Optional trailing text displayed on the tile.
/// - [onPressed]: The callback invoked when the tile is tapped.
class ChooseTile extends StatefulWidget {
final String title;
final VoidCallback? onPressed;
final String? trailingText;
const ChooseTile({
super.key,
required this.title,
@@ -12,6 +13,15 @@ class ChooseTile extends StatefulWidget {
this.onPressed,
});
/// The title text displayed on the tile.
final String title;
/// The callback invoked when the tile is tapped.
final VoidCallback? onPressed;
/// Optional trailing text displayed on the tile.
final String? trailingText;
@override
State<ChooseTile> createState() => _ChooseTileState();
}

View File

@@ -1,11 +1,11 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
/// A custom radio list tile widget that encapsulates a [Radio] button with additional styling and functionality.
/// - [text]: The text to display next to the radio button.
/// - [value]: The value associated with the radio button.
/// - [onContainerTap]: The callback invoked when the container is tapped.
class CustomRadioListTile<T> extends StatelessWidget {
final String text;
final T value;
final ValueChanged<T> onContainerTap;
const CustomRadioListTile({
super.key,
required this.text,
@@ -13,6 +13,15 @@ class CustomRadioListTile<T> extends StatelessWidget {
required this.onContainerTap,
});
/// The text to display next to the radio button.
final String text;
/// The value associated with the radio button.
final T value;
/// The callback invoked when the container is tapped.
final ValueChanged<T> onContainerTap;
@override
Widget build(BuildContext context) {
return GestureDetector(

View File

@@ -3,10 +3,16 @@ import 'package:game_tracker/core/custom_theme.dart';
import 'package:game_tracker/data/dto/group.dart';
import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
/// A tile widget that displays information about a group, including its name and members.
/// - [group]: The group data to be displayed.
/// - [isHighlighted]: Whether the tile should be highlighted.
class GroupTile extends StatelessWidget {
const GroupTile({super.key, required this.group, this.isHighlighted = false});
/// The group data to be displayed.
final Group group;
/// Whether the tile should be highlighted.
final bool isHighlighted;
@override

View File

@@ -1,13 +1,14 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
/// A tile widget that displays a title with an icon and some content below it.
/// - [title]: The title text displayed on the tile.
/// - [icon]: The icon displayed next to the title.
/// - [content]: The content widget displayed below the title.
/// - [padding]: Optional padding for the tile content.
/// - [height]: Optional height for the tile.
/// - [width]: Optional width for the tile.
class InfoTile extends StatefulWidget {
final String title;
final IconData icon;
final Widget content;
final EdgeInsets? padding;
final double? height;
final double? width;
const InfoTile({
super.key,
required this.title,
@@ -18,6 +19,24 @@ class InfoTile extends StatefulWidget {
this.width,
});
/// The title text displayed on the tile.
final String title;
/// The icon displayed next to the title.
final IconData icon;
/// The content widget displayed below the title.
final Widget content;
/// Optional padding for the tile content.
final EdgeInsets? padding;
/// Optional height for the tile.
final double? height;
/// Optional width for the tile.
final double? width;
@override
State<InfoTile> createState() => _InfoTileState();
}

View File

@@ -1,26 +1,41 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
import 'package:game_tracker/data/dto/match.dart';
import 'package:game_tracker/data/dto/player.dart';
import 'package:game_tracker/l10n/generated/app_localizations.dart';
import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
import 'package:intl/intl.dart';
/// A tile widget that displays information about a match, including its name,
/// creation date, associated group, winner, and players.
/// - [match]: The match data to be displayed.
/// - [onTap]: The callback invoked when the tile is tapped.
class MatchTile extends StatefulWidget {
final Match match;
final VoidCallback onTap;
const MatchTile({super.key, required this.match, required this.onTap});
/// The match data to be displayed.
final Match match;
/// The callback invoked when the tile is tapped.
final VoidCallback onTap;
@override
State<MatchTile> createState() => _MatchTileState();
}
class _MatchTileState extends State<MatchTile> {
late final List<Player> _allPlayers;
@override
void initState() {
super.initState();
_allPlayers = _getCombinedPlayers();
}
@override
Widget build(BuildContext context) {
final group = widget.match.group;
final winner = widget.match.winner;
final allPlayers = _getAllPlayers();
final loc = AppLocalizations.of(context);
return GestureDetector(
@@ -114,7 +129,7 @@ class _MatchTileState extends State<MatchTile> {
const SizedBox(height: 12),
],
if (allPlayers.isNotEmpty) ...[
if (_allPlayers.isNotEmpty) ...[
Text(
loc.players,
style: const TextStyle(
@@ -127,7 +142,7 @@ class _MatchTileState extends State<MatchTile> {
Wrap(
spacing: 6,
runSpacing: 6,
children: allPlayers.map((player) {
children: _allPlayers.map((player) {
return TextIconTile(text: player.name, iconEnabled: false);
}).toList(),
),
@@ -138,6 +153,8 @@ class _MatchTileState extends State<MatchTile> {
);
}
/// Formats the given [dateTime] into a human-readable string based on its
/// difference from the current date.
String _formatDate(DateTime dateTime, BuildContext context) {
final now = DateTime.now();
final difference = now.difference(dateTime);
@@ -158,8 +175,10 @@ class _MatchTileState extends State<MatchTile> {
}
}
List<dynamic> _getAllPlayers() {
final allPlayers = <dynamic>[];
/// Retrieves all unique players associated with the match,
/// combining players from both the match and its group.
List<Player> _getCombinedPlayers() {
final allPlayers = <Player>[];
final playerIds = <String>{};
// Add players from game.players

View File

@@ -1,13 +1,14 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
/// A tile widget that displays a title with an icon and a numeric value below it.
/// - [title]: The title text displayed on the tile.
/// - [icon]: The icon displayed next to the title.
/// - [value]: The numeric value displayed below the title.
/// - [height]: Optional height for the tile.
/// - [width]: Optional width for the tile.
/// - [padding]: Optional padding for the tile content.
class QuickInfoTile extends StatefulWidget {
final String title;
final IconData icon;
final int value;
final double? height;
final double? width;
final EdgeInsets? padding;
const QuickInfoTile({
super.key,
required this.title,
@@ -18,6 +19,24 @@ class QuickInfoTile extends StatefulWidget {
this.padding,
});
/// The title text displayed on the tile.
final String title;
/// The icon displayed next to the title.
final IconData icon;
/// The numeric value displayed below the title.
final int value;
/// Optional height for the tile.
final double? height;
/// Optional width for the tile.
final double? width;
/// Optional padding for the tile content.
final EdgeInsets? padding;
@override
State<QuickInfoTile> createState() => _QuickInfoTileState();
}

View File

@@ -1,19 +1,32 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
/// A customizable settings list tile widget that displays an icon, title, and an optional suffix widget.
/// - [icon]: The icon displayed on the left side of the tile.
/// - [title]: The title text displayed next to the icon.
/// - [suffixWidget]: An optional widget displayed on the right side of the tile.
/// - [onPressed]: The callback invoked when the tile is tapped.
class SettingsListTile extends StatelessWidget {
final VoidCallback? onPressed;
final IconData icon;
final String title;
final Widget? suffixWidget;
const SettingsListTile({
super.key,
required this.title,
required this.icon,
required this.title,
this.suffixWidget,
this.onPressed,
});
/// The icon displayed on the left side of the tile.
final IconData icon;
/// The title text displayed next to the icon.
final String title;
/// An optional widget displayed on the right side of the tile.
final Widget? suffixWidget;
/// The callback invoked when the tile is tapped.
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
return Padding(

View File

@@ -4,6 +4,13 @@ import 'package:flutter/material.dart';
import 'package:game_tracker/l10n/generated/app_localizations.dart';
import 'package:game_tracker/presentation/widgets/tiles/info_tile.dart';
/// A tile widget that displays statistical data using horizontal bars.
/// - [icon]: The icon displayed next to the title.
/// - [title]: The title text displayed on the tile.
/// - [width]: The width of the tile.
/// - [values]: A list of tuples containing labels and their corresponding numeric values.
/// - [itemCount]: The maximum number of items to display.
/// - [barColor]: The color of the bars representing the values.
class StatisticsTile extends StatelessWidget {
const StatisticsTile({
super.key,
@@ -15,11 +22,22 @@ class StatisticsTile extends StatelessWidget {
required this.barColor,
});
/// The icon displayed next to the title.
final IconData icon;
/// The title text displayed on the tile.
final String title;
/// The width of the tile.
final double width;
/// A list of tuples containing labels and their corresponding numeric values.
final List<(String, num)> values;
/// The maximum number of items to display.
final int itemCount;
/// The color of the bars representing the values.
final Color barColor;
@override

View File

@@ -1,18 +1,27 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
/// A list tile widget that displays text with an optional icon button.
/// - [text]: The text to display in the tile.
/// - [onPressed]: The callback to be invoked when the icon is pressed.
/// - [iconEnabled]: A boolean to determine if the icon should be displayed.
class TextIconListTile extends StatelessWidget {
final String text;
final VoidCallback? onPressed;
final bool iconEnabled;
const TextIconListTile({
super.key,
required this.text,
this.onPressed,
this.iconEnabled = true,
this.onPressed,
});
/// The text to display in the tile.
final String text;
/// A boolean to determine if the icon should be displayed.
final bool iconEnabled;
/// The callback to be invoked when the icon is pressed.
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
return Container(

View File

@@ -1,18 +1,27 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
/// A tile widget that displays text with an optional icon that can be tapped.
/// - [text]: The text to display in the tile.
/// - [iconEnabled]: A boolean to determine if the icon should be displayed.
/// - [onIconTap]: The callback to be invoked when the icon is tapped.
class TextIconTile extends StatelessWidget {
final String text;
final bool iconEnabled;
final VoidCallback? onIconTap;
const TextIconTile({
super.key,
required this.text,
this.onIconTap,
this.iconEnabled = true,
this.onIconTap,
});
/// The text to display in the tile.
final String text;
/// A boolean to determine if the icon should be displayed.
final bool iconEnabled;
/// The callback to be invoked when the icon is tapped.
final VoidCallback? onIconTap;
@override
Widget build(BuildContext context) {
return Container(

View File

@@ -1,14 +1,14 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
/// A list tile widget that displays a title and description, with optional highlighting and badge.
/// - [title]: The title text displayed on the tile.
/// - [description]: The description text displayed below the title.
/// - [onPressed]: The callback invoked when the tile is tapped.
/// - [isHighlighted]: A boolean to determine if the tile should be highlighted.
/// - [badgeText]: Optional text to display in a badge on the right side of the title.
/// - [badgeColor]: Optional color for the badge background.
class TitleDescriptionListTile extends StatelessWidget {
final String title;
final String description;
final VoidCallback? onPressed;
final bool isHighlighted;
final String? badgeText;
final Color? badgeColor;
const TitleDescriptionListTile({
super.key,
required this.title,
@@ -19,6 +19,24 @@ class TitleDescriptionListTile extends StatelessWidget {
this.badgeColor,
});
/// The title text displayed on the tile.
final String title;
/// The description text displayed below the title.
final String description;
/// The callback invoked when the tile is tapped.
final VoidCallback? onPressed;
/// A boolean to determine if the tile should be highlighted.
final bool isHighlighted;
/// Optional text to display in a badge on the right side of the title.
final String? badgeText;
/// Optional color for the badge background.
final Color? badgeColor;
@override
Widget build(BuildContext context) {
return GestureDetector(