refactor: fix warnings

This commit is contained in:
edde746
2025-12-13 15:37:55 +01:00
parent 18c322f66a
commit 867992e96b
23 changed files with 141 additions and 172 deletions
-8
View File
@@ -56,7 +56,6 @@ class _InputModeTrackerState extends State<InputModeTracker> {
_updateFocusHighlightStrategy(_mode);
// Listen to hardware keyboard events globally
HardwareKeyboard.instance.addHandler(_handleKeyEvent);
RawKeyboard.instance.addListener(_handleRawKeyEvent);
// Register callback for gamepad input to switch to keyboard mode
GamepadService.onGamepadInput = () => _setMode(InputMode.keyboard);
@@ -65,7 +64,6 @@ class _InputModeTrackerState extends State<InputModeTracker> {
@override
void dispose() {
HardwareKeyboard.instance.removeHandler(_handleKeyEvent);
RawKeyboard.instance.removeListener(_handleRawKeyEvent);
GamepadService.onGamepadInput = null;
super.dispose();
}
@@ -79,12 +77,6 @@ class _InputModeTrackerState extends State<InputModeTracker> {
return false;
}
void _handleRawKeyEvent(RawKeyEvent event) {
if (event is RawKeyDownEvent) {
_setMode(InputMode.keyboard);
}
}
void _setMode(InputMode mode) {
if (_mode != mode) {
setState(() => _mode = mode);
+2 -1
View File
@@ -40,8 +40,9 @@ class DownloadProgress {
String _formatBytes(int bytes) {
if (bytes < 1024) return '$bytes B';
if (bytes < 1024 * 1024) return '${(bytes / 1024).toStringAsFixed(1)} KB';
if (bytes < 1024 * 1024 * 1024)
if (bytes < 1024 * 1024 * 1024) {
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
}
return '${(bytes / (1024 * 1024 * 1024)).toStringAsFixed(2)} GB';
}
+3 -2
View File
@@ -11,10 +11,11 @@ class OfflineModeProvider extends ChangeNotifier {
StreamSubscription<Map<String, bool>>? _serverStatusSubscription;
bool _hasNetworkConnection = true;
bool _hasServerConnection = false;
late bool _hasServerConnection;
bool _isInitialized = false;
OfflineModeProvider(this._serverManager);
OfflineModeProvider(this._serverManager)
: _hasServerConnection = _serverManager.onlineServerIds.isNotEmpty;
/// Whether the app is currently in offline mode
/// Offline = no network OR no servers reachable
+6
View File
@@ -26,6 +26,7 @@ import '../utils/app_logger.dart';
import '../utils/provider_extensions.dart';
import '../utils/video_player_navigation.dart';
import '../utils/content_rating_formatter.dart';
import '../utils/layout_constants.dart';
import '../focus/dpad_navigator.dart';
import 'auth_screen.dart';
@@ -467,6 +468,8 @@ class _DiscoverScreenState extends State<DiscoverScreen>
// Wait for libraries and then fetch hubs
final librariesByServer = await librariesFuture;
if (!mounted) return;
// Get hidden libraries to filter from hubs
final hiddenLibrariesProvider = Provider.of<HiddenLibrariesProvider>(
context,
@@ -494,6 +497,7 @@ class _DiscoverScreenState extends State<DiscoverScreen>
appLogger.d(
'Received ${onDeck.length} on deck items and ${filteredHubs.length} hubs from all servers',
);
if (!mounted) return;
setState(() {
_hubs = filteredHubs;
_areHubsLoading = false;
@@ -554,6 +558,7 @@ class _DiscoverScreenState extends State<DiscoverScreen>
}
// Public method to fully reload all content (for profile switches)
@override
void fullRefresh() {
appLogger.d('DiscoverScreen.fullRefresh() called - reloading all content');
// Reload all content including On Deck and content hubs
@@ -782,6 +787,7 @@ class _DiscoverScreenState extends State<DiscoverScreen>
),
],
).then((value) {
if (!context.mounted) return;
if (value == 'switch_profile') {
_handleSwitchProfile(context);
} else if (value == 'logout') {
@@ -244,6 +244,7 @@ class _LibrariesScreenState extends State<LibrariesScreen>
/// If the active tab has already loaded data (often the case after preloading
/// while on another main tab), re-request focus so the first item is focused
/// once the screen is actually shown.
@override
void focusActiveTabIfReady() {
if (_selectedLibraryGlobalKey == null) return;
_focusCurrentTab();
@@ -452,6 +453,7 @@ class _LibrariesScreenState extends State<LibrariesScreen>
}
/// Public method to load a library by key (called from MainScreen side nav)
@override
void loadLibraryByKey(String libraryGlobalKey) {
_loadLibraryContent(libraryGlobalKey);
}
@@ -716,6 +718,7 @@ class _LibrariesScreenState extends State<LibrariesScreen>
}
// Public method to fully reload all content (for profile switches)
@override
void fullRefresh() {
appLogger.d('LibrariesScreen.fullRefresh() called - reloading all content');
// Reload libraries and clear any selected library/filters
+48 -46
View File
@@ -86,53 +86,55 @@ class _SortBottomSheetState extends State<SortBottomSheet> {
: null,
),
Expanded(
child: ListView.builder(
controller: scrollController,
padding: const EdgeInsets.symmetric(vertical: 8),
itemCount: widget.sortOptions.length,
itemBuilder: (context, index) {
final sort = widget.sortOptions[index];
final isSelected = _currentSort?.key == sort.key;
return FocusableRadioListTile<PlexSort>(
focusNode: index == 0 ? _initialFocusNode : null,
title: Text(sort.title),
value: sort,
groupValue: _currentSort,
onChanged: (value) {
if (value != null) {
_handleSortChange(value, value.isDefaultDescending);
}
},
secondary: isSelected
? SegmentedButton<bool>(
showSelectedIcon: false,
segments: const [
ButtonSegment(
value: false,
icon: AppIcon(
Symbols.arrow_upward_rounded,
fill: 1,
size: 16,
),
),
ButtonSegment(
value: true,
icon: AppIcon(
Symbols.arrow_downward_rounded,
fill: 1,
size: 16,
),
),
],
selected: {_currentDescending},
onSelectionChanged: (Set<bool> newSelection) {
_handleSortChange(sort, newSelection.first);
},
)
: null,
);
child: RadioGroup<PlexSort>(
groupValue: _currentSort,
onChanged: (value) {
if (value != null) {
_handleSortChange(value, value.isDefaultDescending);
}
},
child: ListView.builder(
controller: scrollController,
padding: const EdgeInsets.symmetric(vertical: 8),
itemCount: widget.sortOptions.length,
itemBuilder: (context, index) {
final sort = widget.sortOptions[index];
final isSelected = _currentSort?.key == sort.key;
return FocusableRadioListTile<PlexSort>(
focusNode: index == 0 ? _initialFocusNode : null,
title: Text(sort.title),
value: sort,
secondary: isSelected
? SegmentedButton<bool>(
showSelectedIcon: false,
segments: const [
ButtonSegment(
value: false,
icon: AppIcon(
Symbols.arrow_upward_rounded,
fill: 1,
size: 16,
),
),
ButtonSegment(
value: true,
icon: AppIcon(
Symbols.arrow_downward_rounded,
fill: 1,
size: 16,
),
),
],
selected: {_currentDescending},
onSelectionChanged: (Set<bool> newSelection) {
_handleSortChange(sort, newSelection.first);
},
)
: null,
);
},
),
),
),
],
@@ -365,35 +365,36 @@ class _LibraryBrowseTabState
context: context,
builder: (sheetContext) {
final options = _getGroupingOptions();
return ListView.builder(
shrinkWrap: true,
itemCount: options.length,
itemBuilder: (context, index) {
final grouping = options[index];
return RadioListTile<String>(
title: Text(_getGroupingLabel(grouping)),
value: grouping,
groupValue: _selectedGrouping,
onChanged: (value) async {
if (value != null) {
setState(() {
_selectedGrouping = value;
});
return RadioGroup<String>(
groupValue: _selectedGrouping,
onChanged: (value) async {
if (value == null) return;
setState(() {
_selectedGrouping = value;
});
final storage = await StorageService.getInstance();
await storage.saveLibraryGrouping(
widget.library.globalKey,
value,
);
if (!sheetContext.mounted) return;
Navigator.pop(sheetContext);
_loadItems();
}
},
final storage = await StorageService.getInstance();
await storage.saveLibraryGrouping(
widget.library.globalKey,
value,
);
if (!sheetContext.mounted || !mounted) return;
Navigator.pop(sheetContext);
_loadItems();
},
child: ListView.builder(
shrinkWrap: true,
itemCount: options.length,
itemBuilder: (context, index) {
final grouping = options[index];
return RadioListTile<String>(
title: Text(_getGroupingLabel(grouping)),
value: grouping,
);
},
),
);
},
);
+2 -43
View File
@@ -1,10 +1,7 @@
import 'package:flutter/material.dart';
import 'package:plezy/widgets/app_icon.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import '../../services/plex_client.dart';
import '../i18n/strings.g.dart';
import '../utils/app_logger.dart';
import '../utils/provider_extensions.dart';
import '../utils/platform_detector.dart';
@@ -313,7 +310,8 @@ class _MainScreenState extends State<MainScreen> with RouteAware {
);
// Trigger watch state sync now that servers are connected
if (connectedCount > 0 && context.mounted) {
if (connectedCount > 0) {
if (!mounted) return;
context.read<OfflineWatchSyncService>().onServersConnected();
}
}
@@ -460,42 +458,3 @@ class _MainScreenState extends State<MainScreen> with RouteAware {
);
}
}
/// Placeholder widget shown for network-dependent screens when offline
class _OfflinePlaceholder extends StatelessWidget {
const _OfflinePlaceholder();
@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AppIcon(
Symbols.cloud_off_rounded,
fill: 1,
size: 64,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(height: 16),
Text(
t.messages.youAreOffline,
style: Theme.of(context).textTheme.headlineSmall,
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
t.messages.offlineFeatureUnavailable,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
],
),
),
);
}
}
+7 -1
View File
@@ -99,7 +99,10 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
value: 1.0,
strokeWidth: 2.0,
valueColor: AlwaysStoppedAnimation<Color>(
Theme.of(context).colorScheme.primary.withOpacity(0.2),
Theme.of(context)
.colorScheme
.primary
.withValues(alpha: 0.2),
),
),
// Progress circle (indeterminate if no progress, determinate otherwise)
@@ -368,6 +371,8 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
await Future.delayed(const Duration(milliseconds: 100));
}
if (!mounted) return;
if (_seasons.isEmpty) {
if (mounted) {
ScaffoldMessenger.of(
@@ -382,6 +387,7 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
// Get episodes of the first season
List<PlexMetadata> episodes;
if (!mounted) return;
if (widget.isOffline) {
// In offline mode, get episodes from downloads
final downloadProvider = context.read<DownloadProvider>();
+2
View File
@@ -131,6 +131,7 @@ class _SearchScreenState extends State<SearchScreen>
}
/// Focus the search input field
@override
void focusSearchInput() {
WidgetsBinding.instance.addPostFrameCallback((_) {
_searchFocusNode.requestFocus();
@@ -138,6 +139,7 @@ class _SearchScreenState extends State<SearchScreen>
}
// Public method to fully reload all content (for profile switches)
@override
void fullRefresh() {
appLogger.d(
'SearchScreen.fullRefresh() called - clearing search and reloading',
+7 -7
View File
@@ -479,14 +479,14 @@ class _EpisodeCard extends StatelessWidget {
children: [
// Background circle
CircularProgressIndicator(
value: 1.0,
strokeWidth: 1.5,
valueColor: AlwaysStoppedAnimation<Color>(
getMutedColor(
Colors.blue,
).withOpacity(0.3),
),
value: 1.0,
strokeWidth: 1.5,
valueColor: AlwaysStoppedAnimation<Color>(
getMutedColor(
Colors.blue,
).withValues(alpha: 0.3),
),
),
// Progress circle
CircularProgressIndicator(
value: progress?.progressPercent,
+3 -5
View File
@@ -1,5 +1,3 @@
import 'dart:collection';
class LogRedactionManager {
// Size limits for bounded sets (FIFO eviction when exceeded)
static const int _maxTokens = 50;
@@ -7,9 +5,9 @@ class LogRedactionManager {
static const int _maxCustomValues = 50;
// Use LinkedHashSet for FIFO ordering
static final Set<String> _tokens = LinkedHashSet<String>();
static final Set<String> _urls = LinkedHashSet<String>();
static final Set<String> _customValues = LinkedHashSet<String>();
static final Set<String> _tokens = <String>{};
static final Set<String> _urls = <String>{};
static final Set<String> _customValues = <String>{};
static final RegExp _ipv4Pattern = RegExp(
r'\b(\d{1,3})([.-])(\d{1,3})\2(\d{1,3})\2(\d{1,3})\b',
+6 -4
View File
@@ -65,10 +65,12 @@ class DeletionProgressDialog extends StatelessWidget {
Text(
progress.currentOperation!,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(
context,
).textTheme.bodySmall?.color?.withOpacity(0.7),
),
color: Theme.of(context)
.textTheme
.bodySmall
?.color
?.withValues(alpha: 0.7),
),
textAlign: TextAlign.center,
),
],
+9 -4
View File
@@ -48,13 +48,17 @@ class DownloadTreeNode {
// Aggregate status from children
final statuses = children.map((c) => c.status).toSet();
if (statuses.contains(DownloadStatus.downloading))
if (statuses.contains(DownloadStatus.downloading)) {
return DownloadStatus.downloading;
}
if (statuses.contains(DownloadStatus.queued)) return DownloadStatus.queued;
if (statuses.contains(DownloadStatus.paused)) return DownloadStatus.paused;
if (statuses.contains(DownloadStatus.failed)) return DownloadStatus.failed;
if (statuses.every((s) => s == DownloadStatus.completed))
if (statuses.contains(DownloadStatus.failed)) {
return DownloadStatus.failed;
}
if (statuses.every((s) => s == DownloadStatus.completed)) {
return DownloadStatus.completed;
}
return DownloadStatus.queued;
}
}
@@ -146,7 +150,8 @@ class DownloadTreeItem extends StatelessWidget {
CircularProgressIndicator(
value: 1.0,
strokeWidth: 3.0,
valueColor: AlwaysStoppedAnimation<Color>(color.withOpacity(0.2)),
valueColor:
AlwaysStoppedAnimation<Color>(color.withValues(alpha: 0.2)),
),
// Progress circle
CircularProgressIndicator(
+9 -7
View File
@@ -397,13 +397,14 @@ class _DownloadTreeViewState extends State<DownloadTreeView> {
if (canExpand) ...[
const SizedBox(height: 4),
Text(
_getNodeSummary(node),
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.6),
),
Text(
_getNodeSummary(node),
style: theme.textTheme.bodySmall?.copyWith(
color:
theme.colorScheme.onSurface.withValues(alpha: 0.6),
),
],
),
],
// Progress bar
if (node.status == DownloadStatus.downloading ||
@@ -418,7 +419,8 @@ class _DownloadTreeViewState extends State<DownloadTreeView> {
Text(
'${(node.progress * 100).toStringAsFixed(1)}% - ${node.downloadProgress!.speedFormatted}',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.6),
color:
theme.colorScheme.onSurface.withValues(alpha: 0.6),
),
),
],
-1
View File
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:plezy/widgets/app_icon.dart';
import 'package:flutter/services.dart';
import '../focus/focusable_chip_mixin.dart';
import '../focus/input_mode_tracker.dart';
+5 -10
View File
@@ -92,12 +92,6 @@ class FocusableRadioListTile<T> extends StatelessWidget {
/// The value represented by this radio button.
final T value;
/// The currently selected value for this group of radio buttons.
final T? groupValue;
/// Called when the user selects this radio button.
final ValueChanged<T?>? onChanged;
/// Whether this radio button is part of a vertically dense list.
final bool dense;
@@ -107,17 +101,19 @@ class FocusableRadioListTile<T> extends StatelessWidget {
/// Whether this tile should autofocus when first built.
final bool autofocus;
/// Whether the radio tile is interactive.
final bool? enabled;
const FocusableRadioListTile({
super.key,
this.title,
this.subtitle,
this.secondary,
required this.value,
required this.groupValue,
required this.onChanged,
this.dense = false,
this.focusNode,
this.autofocus = false,
this.enabled,
});
@override
@@ -127,11 +123,10 @@ class FocusableRadioListTile<T> extends StatelessWidget {
subtitle: subtitle,
secondary: secondary,
value: value,
groupValue: groupValue,
onChanged: onChanged,
dense: dense,
focusNode: focusNode,
autofocus: autofocus,
enabled: enabled,
);
}
}
-1
View File
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../focus/focusable_chip_mixin.dart';
import '../focus/input_mode_tracker.dart';
+1 -1
View File
@@ -124,7 +124,7 @@ class MediaCardState extends State<MediaCard> {
isOffline: widget.isOffline,
);
if (!mounted) return;
if (!context.mounted) return;
switch (result) {
case MediaNavigationResult.unsupported:
@@ -278,7 +278,7 @@ class _VideoSettingsSheetState extends State<VideoSettingsSheet> {
trailing: Switch(
value: _enableHDR,
onChanged: (_) => _toggleHDR(),
activeColor: Colors.amber,
activeThumbColor: Colors.amber,
),
onTap: _toggleHDR,
),
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:plezy/widgets/app_icon.dart';
import 'package:flutter/services.dart';
import '../../focus/focusable_wrapper.dart';
@@ -1,6 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../../models/plex_media_info.dart';
import '../../../i18n/strings.g.dart';
import '../../../focus/focusable_wrapper.dart';
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../../mpv/mpv.dart';
import '../../../models/plex_media_info.dart';