v1.0.1: Fix Android TV remote control navigation and focus indicators
This commit is contained in:
256
lib/widgets/countries_sidebar.dart
Normal file
256
lib/widgets/countries_sidebar.dart
Normal file
@@ -0,0 +1,256 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CountriesSidebar extends StatelessWidget {
|
||||
final List<String> countries;
|
||||
final String selectedCountry;
|
||||
final String title;
|
||||
final ValueChanged<String> onCountrySelected;
|
||||
final bool isLoading;
|
||||
|
||||
const CountriesSidebar({
|
||||
super.key,
|
||||
required this.countries,
|
||||
required this.selectedCountry,
|
||||
required this.onCountrySelected,
|
||||
this.title = 'Países',
|
||||
this.isLoading = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print('DEBUG: CountriesSidebar.build() called');
|
||||
print('DEBUG: CountriesSidebar received ${countries.length} countries: $countries');
|
||||
print('DEBUG: CountriesSidebar selectedCountry: "$selectedCountry"');
|
||||
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final isLargeScreen = screenWidth > 900;
|
||||
final sidebarWidth = isLargeScreen ? 280.0 : 220.0;
|
||||
final headerHeight = isLargeScreen ? 70.0 : 60.0;
|
||||
final itemHeight = isLargeScreen ? 52.0 : 44.0;
|
||||
final fontSize = isLargeScreen ? 16.0 : 14.0;
|
||||
final headerFontSize = isLargeScreen ? 18.0 : 16.0;
|
||||
final horizontalPadding = isLargeScreen ? 20.0 : 16.0;
|
||||
|
||||
return Container(
|
||||
width: sidebarWidth,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF14141f),
|
||||
border: Border(
|
||||
right: BorderSide(
|
||||
color: Colors.white.withValues(alpha: 0.08),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
height: headerHeight,
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1a1a2e),
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Colors.white.withValues(alpha: 0.08),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.flag,
|
||||
color: Colors.red.shade400,
|
||||
size: isLargeScreen ? 24 : 20,
|
||||
),
|
||||
SizedBox(width: isLargeScreen ? 12 : 10),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: headerFontSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: isLoading && countries.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: isLargeScreen ? 40 : 32,
|
||||
height: isLargeScreen ? 40 : 32,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.red.shade400,
|
||||
strokeWidth: isLargeScreen ? 3 : 2,
|
||||
),
|
||||
),
|
||||
SizedBox(height: isLargeScreen ? 16 : 12),
|
||||
Text(
|
||||
'Cargando países...',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.6),
|
||||
fontSize: fontSize,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: countries.isEmpty
|
||||
? Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(horizontalPadding),
|
||||
child: Text(
|
||||
'No hay países disponibles',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.5),
|
||||
fontSize: fontSize,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: EdgeInsets.symmetric(vertical: isLargeScreen ? 12 : 8),
|
||||
itemCount: countries.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) {
|
||||
return _CountryListItem(
|
||||
name: 'Todos',
|
||||
isSelected: selectedCountry.isEmpty,
|
||||
onTap: () => onCountrySelected(''),
|
||||
itemHeight: itemHeight,
|
||||
fontSize: fontSize,
|
||||
horizontalPadding: horizontalPadding,
|
||||
icon: Icons.apps,
|
||||
);
|
||||
}
|
||||
|
||||
final country = countries[index - 1];
|
||||
return _CountryListItem(
|
||||
name: country,
|
||||
isSelected: selectedCountry == country,
|
||||
onTap: () => onCountrySelected(country),
|
||||
itemHeight: itemHeight,
|
||||
fontSize: fontSize,
|
||||
horizontalPadding: horizontalPadding,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CountryListItem extends StatelessWidget {
|
||||
final String name;
|
||||
final bool isSelected;
|
||||
final VoidCallback onTap;
|
||||
final double itemHeight;
|
||||
final double fontSize;
|
||||
final double horizontalPadding;
|
||||
final IconData? icon;
|
||||
|
||||
const _CountryListItem({
|
||||
required this.name,
|
||||
required this.isSelected,
|
||||
required this.onTap,
|
||||
required this.itemHeight,
|
||||
required this.fontSize,
|
||||
required this.horizontalPadding,
|
||||
this.icon,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: horizontalPadding,
|
||||
vertical: 2,
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
height: itemHeight,
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding * 0.8),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? Colors.red.shade600 : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: isSelected
|
||||
? [
|
||||
BoxShadow(
|
||||
color: Colors.red.withValues(alpha: 0.25),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 3,
|
||||
height: isSelected ? 20 : 0,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? Colors.white : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
SizedBox(width: isSelected ? 12 : 15),
|
||||
if (icon != null) ...[
|
||||
Icon(
|
||||
icon,
|
||||
color: isSelected ? Colors.white : Colors.white.withValues(alpha: 0.6),
|
||||
size: fontSize + 2,
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
] else ...[
|
||||
Icon(
|
||||
Icons.circle,
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: Colors.white.withValues(alpha: 0.3),
|
||||
size: 6,
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
],
|
||||
Expanded(
|
||||
child: Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: Colors.white.withValues(alpha: 0.7),
|
||||
fontSize: fontSize,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
|
||||
letterSpacing: 0.3,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (isSelected)
|
||||
Icon(
|
||||
Icons.check,
|
||||
color: Colors.white,
|
||||
size: fontSize + 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
225
lib/widgets/simple_countries_sidebar.dart
Normal file
225
lib/widgets/simple_countries_sidebar.dart
Normal file
@@ -0,0 +1,225 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SimpleCountriesSidebar extends StatelessWidget {
|
||||
final List<String> countries;
|
||||
final String selectedCountry;
|
||||
final ValueChanged<String> onCountrySelected;
|
||||
final bool isLoading;
|
||||
final bool isOrganizing;
|
||||
final bool showFootballCategory;
|
||||
final VoidCallback? onFootballSelected;
|
||||
|
||||
const SimpleCountriesSidebar({
|
||||
super.key,
|
||||
required this.countries,
|
||||
required this.selectedCountry,
|
||||
required this.onCountrySelected,
|
||||
this.isLoading = false,
|
||||
this.isOrganizing = false,
|
||||
this.showFootballCategory = false,
|
||||
this.onFootballSelected,
|
||||
});
|
||||
|
||||
static const String _footballCategoryName = 'Fútbol Argentino';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print('🔥 SIDEBAR BUILD ============================================');
|
||||
print('🔥 SIDEBAR BUILD - Countries count: ${countries.length}');
|
||||
print('🔥 SIDEBAR BUILD - Is Loading: $isLoading');
|
||||
print('🔥 SIDEBAR BUILD - Is Organizing: $isOrganizing');
|
||||
print('🔥 SIDEBAR BUILD - Countries list: $countries');
|
||||
print('🔥 SIDEBAR BUILD - Selected country: "$selectedCountry"');
|
||||
|
||||
if (countries.isNotEmpty) {
|
||||
print('🔥 SIDEBAR BUILD - First 10 countries:');
|
||||
for (int i = 0; i < countries.length && i < 10; i++) {
|
||||
print('🔥 SIDEBAR BUILD [${i + 1}] "${countries[i]}"');
|
||||
}
|
||||
}
|
||||
print('🔥 SIDEBAR BUILD ============================================');
|
||||
|
||||
return Container(
|
||||
width: 250,
|
||||
color: Colors.grey[900],
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
color: Colors.red,
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.public, color: Colors.white),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'PAÍSES',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// List
|
||||
Expanded(
|
||||
child: isOrganizing || (isLoading && countries.isEmpty)
|
||||
? const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(color: Colors.red),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Organizando países...',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: countries.isEmpty
|
||||
? const Center(
|
||||
child: Text(
|
||||
'No hay países',
|
||||
style: TextStyle(color: Colors.white54),
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
itemCount: _getItemCount(),
|
||||
itemBuilder: (context, index) {
|
||||
return _buildItemAtIndex(context, index);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCountryItem(String name, bool isSelected, VoidCallback onTap) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? Colors.red : Colors.transparent,
|
||||
border: Border(
|
||||
left: BorderSide(
|
||||
color: isSelected ? Colors.white : Colors.transparent,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
int _getItemCount() {
|
||||
int count = countries.length + 1; // +1 for "Todos"
|
||||
if (showFootballCategory) {
|
||||
count += 1; // +1 for "Fútbol Argentino"
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
Widget _buildItemAtIndex(BuildContext context, int index) {
|
||||
if (index == 0) {
|
||||
return _buildCountryItem(
|
||||
'Todos',
|
||||
selectedCountry.isEmpty,
|
||||
() => onCountrySelected(''),
|
||||
);
|
||||
}
|
||||
|
||||
// Find insertion point for "Fútbol Argentino" (after Perú)
|
||||
final peruIndex = countries.indexOf('Perú');
|
||||
final footballInsertIndex = peruIndex >= 0 ? peruIndex + 1 : countries.length;
|
||||
|
||||
if (showFootballCategory) {
|
||||
// Adjust for "Todos" at index 0 and "Fútbol Argentino" after Perú
|
||||
if (index == footballInsertIndex + 1) {
|
||||
return _buildFootballItem();
|
||||
}
|
||||
|
||||
// Map the adjusted index to the actual country list
|
||||
int countryIndex;
|
||||
if (index <= footballInsertIndex) {
|
||||
// Before football item
|
||||
countryIndex = index - 1;
|
||||
} else {
|
||||
// After football item
|
||||
countryIndex = index - 2;
|
||||
}
|
||||
|
||||
if (countryIndex >= 0 && countryIndex < countries.length) {
|
||||
final country = countries[countryIndex];
|
||||
return _buildCountryItem(
|
||||
country,
|
||||
selectedCountry == country,
|
||||
() => onCountrySelected(country),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Normal behavior without football category
|
||||
final country = countries[index - 1];
|
||||
return _buildCountryItem(
|
||||
country,
|
||||
selectedCountry == country,
|
||||
() => onCountrySelected(country),
|
||||
);
|
||||
}
|
||||
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
Widget _buildFootballItem() {
|
||||
final isSelected = selectedCountry == _footballCategoryName;
|
||||
return InkWell(
|
||||
onTap: onFootballSelected,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? Colors.green[700] : Colors.green[900]?.withOpacity(0.3),
|
||||
border: Border(
|
||||
left: BorderSide(
|
||||
color: isSelected ? Colors.white : Colors.green[400]!,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.sports_soccer,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_footballCategoryName,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user