tentar aresolver a home

This commit is contained in:
2026-06-08 14:54:04 +01:00
parent 7d2f3c4679
commit 947e119dba
5 changed files with 264 additions and 116 deletions

View File

@@ -219,7 +219,8 @@ class _HomeScreenState extends State<HomeScreen> {
padding: EdgeInsets.all(10.0 * context.sf),
child: InkWell(
borderRadius: BorderRadius.circular(100),
onTap: () async {
onTap: () async {
debugPrint('Home: settings button tapped');
await Navigator.push(
context,
MaterialPageRoute(
@@ -290,98 +291,120 @@ class _HomeScreenState extends State<HomeScreen> {
}
void _showTeamSelector(BuildContext context) {
showModalBottomSheet(
context: context,
backgroundColor: Theme.of(context).colorScheme.surface,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.vertical(top: Radius.circular(20 * context.sf)),
),
builder: (context) {
return StreamBuilder<List<Map<String, dynamic>>>(
stream: _teamController.teamsStream,
builder: (context, snapshot) {
if (!snapshot.hasData &&
snapshot.connectionState == ConnectionState.waiting) {
return const SizedBox(
height: 200,
child: Center(child: CircularProgressIndicator()));
}
if (!snapshot.hasData || snapshot.data!.isEmpty) {
return SizedBox(
height: 200 * context.sf,
child: Center(
child: Text("Nenhuma equipa criada.",
style: TextStyle(
color:
Theme.of(context).colorScheme.onSurface))),
);
}
debugPrint('showTeamSelector called');
final isWide = MediaQuery.of(context).size.width >= 900;
final teams = snapshot.data!;
return ListView.builder(
shrinkWrap: true,
itemCount: teams.length,
itemBuilder: (context, index) {
final team = teams[index];
final String? logoUrl = team['image_url'];
return ListTile(
leading: ClipOval(
child: Container(
width: 36 * context.sf,
height: 36 * context.sf,
color: AppTheme.primaryRed.withOpacity(0.1),
child: (logoUrl != null && logoUrl.isNotEmpty)
? CachedNetworkImage(
imageUrl: logoUrl,
fit: BoxFit.cover,
placeholder: (context, url) => Icon(
Icons.shield,
color: AppTheme.primaryRed,
size: 20 * context.sf),
errorWidget: (context, url, error) => Icon(
Icons.shield,
color: AppTheme.primaryRed,
size: 20 * context.sf),
)
: Icon(Icons.shield,
color: AppTheme.primaryRed,
size: 20 * context.sf),
),
),
title: Text(
team['name'] ?? 'Sem Nome',
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.bold),
),
onTap: () async {
setState(() {
_selectedTeamId = team['id'].toString();
_selectedTeamName = team['name'] ?? 'Desconhecido';
_selectedTeamLogo = logoUrl;
_teamWins = int.tryParse(
team['wins']?.toString() ?? '0') ??
0;
_teamLosses = int.tryParse(
team['losses']?.toString() ?? '0') ??
0;
_teamDraws = int.tryParse(
team['draws']?.toString() ?? '0') ??
0;
});
await _saveSelectedTeam();
if (context.mounted) Navigator.pop(context);
},
);
},
Widget builderContent(BuildContext ctx) {
return StreamBuilder<List<Map<String, dynamic>>>(
stream: _teamController.teamsStream,
builder: (context, snapshot) {
if (!snapshot.hasData &&
snapshot.connectionState == ConnectionState.waiting) {
return const SizedBox(
height: 200,
child: Center(child: CircularProgressIndicator()));
}
if (!snapshot.hasData || snapshot.data!.isEmpty) {
return SizedBox(
height: 200 * context.sf,
child: Center(
child: Text("Nenhuma equipa criada.",
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface))),
);
},
);
},
);
}
final teams = snapshot.data!;
return ListView.builder(
shrinkWrap: true,
itemCount: teams.length,
itemBuilder: (context, index) {
final team = teams[index];
final String? logoUrl = team['image_url'];
return ListTile(
leading: ClipOval(
child: Container(
width: 36 * context.sf,
height: 36 * context.sf,
color: AppTheme.primaryRed.withOpacity(0.1),
child: (logoUrl != null && logoUrl.isNotEmpty)
? CachedNetworkImage(
imageUrl: logoUrl,
fit: BoxFit.cover,
placeholder: (context, url) => Icon(
Icons.shield,
color: AppTheme.primaryRed,
size: 20 * context.sf),
errorWidget: (context, url, error) => Icon(
Icons.shield,
color: AppTheme.primaryRed,
size: 20 * context.sf),
)
: Icon(Icons.shield,
color: AppTheme.primaryRed,
size: 20 * context.sf),
),
),
title: Text(
team['name'] ?? 'Sem Nome',
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.bold),
),
onTap: () async {
setState(() {
_selectedTeamId = team['id'].toString();
_selectedTeamName = team['name'] ?? 'Desconhecido';
_selectedTeamLogo = logoUrl;
_teamWins = int.tryParse(
team['wins']?.toString() ?? '0') ??
0;
_teamLosses = int.tryParse(
team['losses']?.toString() ?? '0') ??
0;
_teamDraws = int.tryParse(
team['draws']?.toString() ?? '0') ??
0;
});
await _saveSelectedTeam();
if (context.mounted) Navigator.pop(context);
},
);
},
);
},
);
}
if (isWide) {
showDialog(
context: context,
builder: (ctx) {
return Dialog(
insetPadding: EdgeInsets.symmetric(horizontal: 200 * context.sf, vertical: 80 * context.sf),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12 * context.sf)),
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: 600 * context.sf),
child: Padding(
padding: EdgeInsets.all(16 * context.sf),
child: builderContent(ctx),
),
),
);
},
);
} else {
showModalBottomSheet(
context: context,
backgroundColor: Theme.of(context).colorScheme.surface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20 * context.sf)),
),
builder: (context) => builderContent(context),
);
}
}
Widget _buildHomeContent(BuildContext context) {