From d447632863839b30551b52a68363558b4a34effc Mon Sep 17 00:00:00 2001 From: leok18 <178525594+leok18@users.noreply.github.com> Date: Tue, 4 Nov 2025 20:29:04 -0800 Subject: [PATCH 1/3] debounce team lookup text --- .vscode/settings.json | 12 ++++----- lib/pages/team_lookup/team_lookup.dart | 36 ++++++++++++++++---------- lib/reusable/debouncer.dart | 21 +++++++++++++++ 3 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 lib/reusable/debouncer.dart diff --git a/.vscode/settings.json b/.vscode/settings.json index be44b5af..68491eeb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { - "diffEditor.codeLens": true, - "editor.tabCompletion": "on", - "discord.enabled": true, - "cmake.configureOnOpen": false, - "java.configuration.updateBuildConfiguration": "automatic" -} \ No newline at end of file + "diffEditor.codeLens": true, + "editor.tabCompletion": "on", + "discord.enabled": true, + "cmake.configureOnOpen": false, + "java.configuration.updateBuildConfiguration": "automatic" +} diff --git a/lib/pages/team_lookup/team_lookup.dart b/lib/pages/team_lookup/team_lookup.dart index 2d6dc7b1..30ce2d71 100644 --- a/lib/pages/team_lookup/team_lookup.dart +++ b/lib/pages/team_lookup/team_lookup.dart @@ -8,6 +8,7 @@ import 'package:scouting_dashboard_app/pages/team_lookup/edit_team_lookup_flag.d import 'package:scouting_dashboard_app/pages/team_lookup/tabs/team_lookup_breakdowns.dart'; import 'package:scouting_dashboard_app/pages/team_lookup/tabs/team_lookup_categories.dart'; import 'package:scouting_dashboard_app/pages/team_lookup/tabs/team_lookup_notes.dart'; +import 'package:scouting_dashboard_app/reusable/debouncer.dart'; import 'package:scouting_dashboard_app/reusable/flag_models.dart'; import 'package:scouting_dashboard_app/reusable/page_body.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -22,6 +23,7 @@ class TeamLookupPage extends StatefulWidget { } class _TeamLookupPageState extends State { + final debouncer = Debouncer(delay: const Duration(milliseconds: 200)); String teamFieldValue = ""; TextEditingController? teamFieldController; int? teamNumberForAnalysis; @@ -70,12 +72,16 @@ class _TeamLookupPageState extends State { ), keyboardType: TextInputType.number, onChanged: (value) { - setState(() { - teamFieldValue = value; - if (int.tryParse(value) != null) { - teamNumberForAnalysis = int.parse(value); - } - updateIncrement++; + debouncer.run(() { + setState(() { + teamFieldValue = value; + if (int.tryParse(value) != null) { + teamNumberForAnalysis = int.parse(value); + } else { + teamNumberForAnalysis = null; + } + updateIncrement++; + }); }); }, controller: teamFieldController, @@ -203,13 +209,15 @@ class _TeamLookupFlagState extends State { return prefs == null || int.tryParse(widget.team) == null ? Container() - : NetworkFlag( - team: int.parse(widget.team), - flag: FlagConfiguration.fromJson( - jsonDecode( - prefs!.getString('team_lookup_flag')!, - ), - ), - ); + : prefs!.getString('team_lookup_flag') == null + ? Container() + : NetworkFlag( + team: int.parse(widget.team), + flag: FlagConfiguration.fromJson( + jsonDecode( + prefs!.getString('team_lookup_flag')!, + ), + ), + ); } } diff --git a/lib/reusable/debouncer.dart b/lib/reusable/debouncer.dart new file mode 100644 index 00000000..cbad1792 --- /dev/null +++ b/lib/reusable/debouncer.dart @@ -0,0 +1,21 @@ +import 'dart:async'; + +import 'package:flutter/foundation.dart'; + +class Debouncer { + final Duration delay; + Timer? _timer; + + Debouncer({required this.delay}); + + void run(VoidCallback action) { + _timer?.cancel(); + _timer = Timer(delay, action); + // action(); + } + + void dispose() { + _timer?.cancel(); + _timer = null; + } +} From e168b436973962faefd8ebad0157200787aa6e82 Mon Sep 17 00:00:00 2001 From: MangoSwirl Date: Tue, 4 Nov 2025 22:16:37 -0800 Subject: [PATCH 2/3] Delete commented-out code --- lib/reusable/debouncer.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/reusable/debouncer.dart b/lib/reusable/debouncer.dart index cbad1792..2fa08553 100644 --- a/lib/reusable/debouncer.dart +++ b/lib/reusable/debouncer.dart @@ -11,7 +11,6 @@ class Debouncer { void run(VoidCallback action) { _timer?.cancel(); _timer = Timer(delay, action); - // action(); } void dispose() { From 3c6ebc78a62a923b26ff49febfecbce293ca7585 Mon Sep 17 00:00:00 2001 From: leok18 <178525594+leok18@users.noreply.github.com> Date: Thu, 6 Nov 2025 15:50:22 -0800 Subject: [PATCH 3/3] remove nested ternaries --- lib/pages/team_lookup/team_lookup.dart | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/pages/team_lookup/team_lookup.dart b/lib/pages/team_lookup/team_lookup.dart index 30ce2d71..9cf6e586 100644 --- a/lib/pages/team_lookup/team_lookup.dart +++ b/lib/pages/team_lookup/team_lookup.dart @@ -207,17 +207,18 @@ class _TeamLookupFlagState extends State { Widget build(BuildContext context) { if (loadingTeam != widget.team) load(); - return prefs == null || int.tryParse(widget.team) == null - ? Container() - : prefs!.getString('team_lookup_flag') == null - ? Container() - : NetworkFlag( - team: int.parse(widget.team), - flag: FlagConfiguration.fromJson( - jsonDecode( - prefs!.getString('team_lookup_flag')!, - ), - ), - ); + if (prefs == null || + int.tryParse(widget.team) == null || + prefs!.getString('team_lookup_flag') == null) { + return Container(); + } + return NetworkFlag( + team: int.parse(widget.team), + flag: FlagConfiguration.fromJson( + jsonDecode( + prefs!.getString('team_lookup_flag')!, + ), + ), + ); } }