v1.0.2: Fix syntax error and complete Android TV remote navigation

This commit is contained in:
2026-02-25 23:33:37 -03:00
parent 19b45152f8
commit 5d38b89a53
2 changed files with 281 additions and 188 deletions

View File

@@ -290,8 +290,6 @@ class _HomeScreenState extends State<HomeScreen> {
children: [ children: [
Expanded( Expanded(
flex: 2, flex: 2,
child: Focus(
autofocus: _focusedIndex == 0,
child: _DashboardCard( child: _DashboardCard(
title: 'LIVE TV', title: 'LIVE TV',
icon: Icons.tv, icon: Icons.tv,
@@ -304,14 +302,11 @@ class _HomeScreenState extends State<HomeScreen> {
onTap: _showLiveCategories, onTap: _showLiveCategories,
), ),
), ),
),
SizedBox(width: cardSpacing), SizedBox(width: cardSpacing),
Expanded( Expanded(
child: Column( child: Column(
children: [ children: [
Expanded( Expanded(
child: Focus(
autofocus: _focusedIndex == 1,
child: _DashboardCard( child: _DashboardCard(
title: 'MOVIES', title: 'MOVIES',
icon: Icons.play_circle_fill, icon: Icons.play_circle_fill,
@@ -324,14 +319,11 @@ class _HomeScreenState extends State<HomeScreen> {
onTap: _showMovies, onTap: _showMovies,
), ),
), ),
),
SizedBox(height: cardSpacing), SizedBox(height: cardSpacing),
Expanded( Expanded(
child: Focus(
autofocus: _focusedIndex == 2,
child: _DashboardCard( child: _DashboardCard(
title: 'SERIES', title: 'SERIES',
icon: Icons.movie, icon: Icons.tv,
isLarge: _isLargeScreen, isLarge: _isLargeScreen,
gradient: const LinearGradient( gradient: const LinearGradient(
colors: [Color(0xFF9c27b0), Color(0xFF03a9f4)], colors: [Color(0xFF9c27b0), Color(0xFF03a9f4)],
@@ -341,7 +333,6 @@ class _HomeScreenState extends State<HomeScreen> {
onTap: _showSeries, onTap: _showSeries,
), ),
), ),
),
], ],
), ),
), ),
@@ -383,7 +374,7 @@ class _HomeScreenState extends State<HomeScreen> {
} }
} }
class _DashboardCard extends StatelessWidget { class _DashboardCard extends StatefulWidget {
final String title; final String title;
final IconData icon; final IconData icon;
final Gradient gradient; final Gradient gradient;
@@ -398,35 +389,71 @@ class _DashboardCard extends StatelessWidget {
this.isLarge = false, this.isLarge = false,
}); });
@override
State<_DashboardCard> createState() => _DashboardCardState();
}
class _DashboardCardState extends State<_DashboardCard> {
bool _hasFocus = false;
void _handleTap() {
widget.onTap();
}
void _handleKeyEvent(KeyEvent event) {
if (event is KeyDownEvent) {
if (event.logicalKey == LogicalKeyboardKey.enter ||
event.logicalKey == LogicalKeyboardKey.select ||
event.logicalKey == LogicalKeyboardKey.space) {
_handleTap();
}
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final iconSize = isLarge ? 80.0 : 60.0; final iconSize = widget.isLarge ? 80.0 : 60.0;
final titleSize = isLarge ? 32.0 : 24.0; final titleSize = widget.isLarge ? 32.0 : 24.0;
final bgIconSize = isLarge ? 200.0 : 150.0; final bgIconSize = widget.isLarge ? 200.0 : 150.0;
return Focus(
canRequestFocus: true, return FocusableActionDetector(
child: Builder( actions: <Type, Action<Intent>>{
builder: (context) { ActivateIntent: CallbackAction<ActivateIntent>(
final hasFocus = Focus.of(context).hasFocus; onInvoke: (intent) {
return InkWell( _handleTap();
onTap: onTap, return null;
borderRadius: BorderRadius.circular(20), },
),
ButtonActivateIntent: CallbackAction<ButtonActivateIntent>(
onInvoke: (intent) {
_handleTap();
return null;
},
),
},
onFocusChange: (hasFocus) {
setState(() {
_hasFocus = hasFocus;
});
},
child: GestureDetector(
onTap: _handleTap,
child: AnimatedContainer( child: AnimatedContainer(
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: gradient, gradient: widget.gradient,
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: hasFocus ? Colors.white.withValues(alpha: 0.4) : Colors.black.withValues(alpha: 0.3), color: _hasFocus ? Colors.white.withValues(alpha: 0.6) : Colors.black.withValues(alpha: 0.3),
blurRadius: hasFocus ? 30 : 15, blurRadius: _hasFocus ? 35 : 15,
spreadRadius: hasFocus ? 4 : 0, spreadRadius: _hasFocus ? 6 : 0,
offset: const Offset(0, 8), offset: const Offset(0, 8),
), ),
], ],
border: hasFocus border: _hasFocus
? Border.all(color: Colors.white, width: 4) ? Border.all(color: Colors.white, width: 5)
: Border.all(color: Colors.transparent, width: 4), : Border.all(color: Colors.transparent, width: 5),
), ),
child: Stack( child: Stack(
children: [ children: [
@@ -434,7 +461,7 @@ class _DashboardCard extends StatelessWidget {
right: -40, right: -40,
bottom: -40, bottom: -40,
child: Icon( child: Icon(
icon, widget.icon,
size: bgIconSize, size: bgIconSize,
color: Colors.white.withValues(alpha: 0.1), color: Colors.white.withValues(alpha: 0.1),
), ),
@@ -443,10 +470,10 @@ class _DashboardCard extends StatelessWidget {
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon(icon, size: iconSize, color: Colors.white), Icon(widget.icon, size: iconSize, color: Colors.white),
const SizedBox(height: 16), const SizedBox(height: 16),
Text( Text(
title, widget.title,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: titleSize, fontSize: titleSize,
@@ -460,8 +487,6 @@ class _DashboardCard extends StatelessWidget {
], ],
), ),
), ),
);
},
), ),
); );
} }
@@ -791,7 +816,7 @@ class _ContentListScreenState extends State<ContentListScreen> {
} }
} }
class _ChannelCard extends StatelessWidget { class _ChannelCard extends StatefulWidget {
final XtreamStream stream; final XtreamStream stream;
final bool isSeries; final bool isSeries;
final VoidCallback onTap; final VoidCallback onTap;
@@ -804,30 +829,57 @@ class _ChannelCard extends StatelessWidget {
this.isLarge = false, this.isLarge = false,
}); });
@override
State<_ChannelCard> createState() => _ChannelCardState();
}
class _ChannelCardState extends State<_ChannelCard> {
bool _hasFocus = false;
void _handleTap() {
widget.onTap();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final textSize = isLarge ? 16.0 : 12.0; final textSize = widget.isLarge ? 16.0 : 12.0;
final ratingFontSize = isLarge ? 14.0 : 10.0; final ratingFontSize = widget.isLarge ? 14.0 : 10.0;
final placeholderIconSize = isLarge ? 56.0 : 40.0; final placeholderIconSize = widget.isLarge ? 56.0 : 40.0;
final padding = isLarge ? 12.0 : 8.0; final padding = widget.isLarge ? 12.0 : 8.0;
final ratingPaddingH = isLarge ? 10.0 : 6.0; final ratingPaddingH = widget.isLarge ? 10.0 : 6.0;
final ratingPaddingV = isLarge ? 4.0 : 2.0; final ratingPaddingV = widget.isLarge ? 4.0 : 2.0;
return Focus( return FocusableActionDetector(
child: Builder( actions: <Type, Action<Intent>>{
builder: (context) { ActivateIntent: CallbackAction<ActivateIntent>(
final hasFocus = Focus.of(context).hasFocus; onInvoke: (intent) {
return GestureDetector( _handleTap();
onTap: onTap, return null;
},
),
ButtonActivateIntent: CallbackAction<ButtonActivateIntent>(
onInvoke: (intent) {
_handleTap();
return null;
},
),
},
onFocusChange: (hasFocus) {
setState(() {
_hasFocus = hasFocus;
});
},
child: GestureDetector(
onTap: _handleTap,
child: AnimatedContainer( child: AnimatedContainer(
duration: const Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.grey[900], color: Colors.grey[900],
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
border: Border.all( border: Border.all(
color: hasFocus ? Colors.red : Colors.red.withValues(alpha: 0.3), color: _hasFocus ? Colors.red : Colors.red.withValues(alpha: 0.3),
width: hasFocus ? 3 : 1, width: _hasFocus ? 3 : 1,
), ),
boxShadow: hasFocus boxShadow: _hasFocus
? [ ? [
BoxShadow( BoxShadow(
color: Colors.red.withValues(alpha: 0.3), color: Colors.red.withValues(alpha: 0.3),
@@ -839,11 +891,11 @@ class _ChannelCard extends StatelessWidget {
), ),
child: Stack( child: Stack(
children: [ children: [
if (stream.streamIcon != null && stream.streamIcon!.isNotEmpty) if (widget.stream.streamIcon != null && widget.stream.streamIcon!.isNotEmpty)
ClipRRect( ClipRRect(
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
child: Image.network( child: Image.network(
stream.streamIcon!, widget.stream.streamIcon!,
width: double.infinity, width: double.infinity,
height: double.infinity, height: double.infinity,
fit: BoxFit.cover, fit: BoxFit.cover,
@@ -870,7 +922,7 @@ class _ChannelCard extends StatelessWidget {
left: padding, left: padding,
right: padding, right: padding,
child: Text( child: Text(
stream.name, widget.stream.name,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: textSize, fontSize: textSize,
@@ -880,7 +932,7 @@ class _ChannelCard extends StatelessWidget {
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ),
if (stream.rating != null) if (widget.stream.rating != null)
Positioned( Positioned(
top: padding, top: padding,
right: padding, right: padding,
@@ -891,7 +943,7 @@ class _ChannelCard extends StatelessWidget {
borderRadius: BorderRadius.circular(6), borderRadius: BorderRadius.circular(6),
), ),
child: Text( child: Text(
stream.rating!, widget.stream.rating!,
style: TextStyle( style: TextStyle(
color: Colors.black, color: Colors.black,
fontSize: ratingFontSize, fontSize: ratingFontSize,
@@ -903,8 +955,6 @@ class _ChannelCard extends StatelessWidget {
], ],
), ),
), ),
);
},
), ),
); );
} }
@@ -914,7 +964,7 @@ class _ChannelCard extends StatelessWidget {
color: Colors.grey[800], color: Colors.grey[800],
child: Center( child: Center(
child: Icon( child: Icon(
isSeries ? Icons.tv : Icons.play_circle_outline, widget.isSeries ? Icons.tv : Icons.play_circle_outline,
color: Colors.red, color: Colors.red,
size: iconSize, size: iconSize,
), ),

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class SimpleCountriesSidebar extends StatelessWidget { class SimpleCountriesSidebar extends StatelessWidget {
final List<String> countries; final List<String> countries;
@@ -101,15 +102,33 @@ class SimpleCountriesSidebar extends StatelessWidget {
} }
Widget _buildCountryItem(String name, bool isSelected, VoidCallback onTap) { Widget _buildCountryItem(String name, bool isSelected, VoidCallback onTap) {
return InkWell( return FocusableActionDetector(
actions: <Type, Action<Intent>>{
ActivateIntent: CallbackAction<ActivateIntent>(
onInvoke: (intent) {
onTap();
return null;
},
),
ButtonActivateIntent: CallbackAction<ButtonActivateIntent>(
onInvoke: (intent) {
onTap();
return null;
},
),
},
child: Builder(
builder: (context) {
final hasFocus = Focus.of(context).hasFocus;
return GestureDetector(
onTap: onTap, onTap: onTap,
child: Container( child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isSelected ? Colors.red : Colors.transparent, color: isSelected ? Colors.red : (hasFocus ? Colors.red.withValues(alpha: 0.5) : Colors.transparent),
border: Border( border: Border(
left: BorderSide( left: BorderSide(
color: isSelected ? Colors.white : Colors.transparent, color: isSelected ? Colors.white : (hasFocus ? Colors.white : Colors.transparent),
width: 4, width: 4,
), ),
), ),
@@ -124,6 +143,9 @@ class SimpleCountriesSidebar extends StatelessWidget {
), ),
), ),
); );
},
),
);
} }
int _getItemCount() { int _getItemCount() {
@@ -186,15 +208,33 @@ class SimpleCountriesSidebar extends StatelessWidget {
Widget _buildFootballItem() { Widget _buildFootballItem() {
final isSelected = selectedCountry == _footballCategoryName; final isSelected = selectedCountry == _footballCategoryName;
return InkWell( return FocusableActionDetector(
actions: <Type, Action<Intent>>{
ActivateIntent: CallbackAction<ActivateIntent>(
onInvoke: (intent) {
onFootballSelected?.call();
return null;
},
),
ButtonActivateIntent: CallbackAction<ButtonActivateIntent>(
onInvoke: (intent) {
onFootballSelected?.call();
return null;
},
),
},
child: Builder(
builder: (context) {
final hasFocus = Focus.of(context).hasFocus;
return GestureDetector(
onTap: onFootballSelected, onTap: onFootballSelected,
child: Container( child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration( decoration: BoxDecoration(
color: isSelected ? Colors.green[700] : Colors.green[900]?.withOpacity(0.3), color: isSelected ? Colors.green[700] : (hasFocus ? Colors.green[700]?.withOpacity(0.8) : Colors.green[900]?.withOpacity(0.3)),
border: Border( border: Border(
left: BorderSide( left: BorderSide(
color: isSelected ? Colors.white : Colors.green[400]!, color: isSelected ? Colors.white : (hasFocus ? Colors.white : Colors.green[400]!),
width: 4, width: 4,
), ),
), ),
@@ -221,5 +261,8 @@ class SimpleCountriesSidebar extends StatelessWidget {
), ),
), ),
); );
},
),
);
} }
} }