tentar aresolver a home
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:playmaker/classe/theme.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../controllers/team_controller.dart';
|
||||
import '../controllers/active_team.dart';
|
||||
import '../utils/size_extension.dart';
|
||||
|
||||
class StatusPage extends StatefulWidget {
|
||||
@@ -44,6 +45,32 @@ class _StatusPageState extends State<StatusPage> {
|
||||
if (_selectedTeamId == null) {
|
||||
_loadSelectedTeamFallback();
|
||||
}
|
||||
|
||||
// Listen to global active team changes (e.g., when user marks favorite)
|
||||
globalActiveTeam.addListener(_onGlobalActiveTeamChanged);
|
||||
|
||||
// Se já existe um globalActiveTeam no momento da abertura da página, aplica-o
|
||||
final atNow = globalActiveTeam.value;
|
||||
if (atNow != null) {
|
||||
_selectedTeamId = atNow.id;
|
||||
_selectedTeamName = atNow.name;
|
||||
_selectedTeamLogo = atNow.logo;
|
||||
}
|
||||
}
|
||||
|
||||
void _onGlobalActiveTeamChanged() {
|
||||
final at = globalActiveTeam.value;
|
||||
if (!mounted) return;
|
||||
|
||||
// Atualiza sempre para a equipa ativa global (favorita). Isto força a Status
|
||||
// a mostrar a equipa marcada como favorita assim que o utilizador a define.
|
||||
if (at != null) {
|
||||
setState(() {
|
||||
_selectedTeamId = at.id;
|
||||
_selectedTeamName = at.name;
|
||||
_selectedTeamLogo = at.logo;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
String _prefsKey(String key) {
|
||||
@@ -238,6 +265,12 @@ class _StatusPageState extends State<StatusPage> {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
globalActiveTeam.removeListener(_onGlobalActiveTeamChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> _aggregateStats(
|
||||
List<dynamic> stats, List<dynamic> games, List<dynamic> members) {
|
||||
Map<String, Map<String, dynamic>> aggregated = {};
|
||||
|
||||
Reference in New Issue
Block a user