eliminar e tentativa de partilhar
This commit is contained in:
@@ -31,7 +31,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
final _supabase = Supabase.instance.client;
|
||||
|
||||
String? _avatarUrl;
|
||||
bool _isMemoryLoaded = false; // 👈 A variável mágica que impede o "piscar" inicial
|
||||
bool _isMemoryLoaded = false; // A variável mágica que impede o "piscar" inicial
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -39,7 +39,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
_loadUserAvatar();
|
||||
}
|
||||
|
||||
// 👇 FUNÇÃO OTIMIZADA: Carrega da memória instantaneamente e atualiza em background
|
||||
// FUNÇÃO OTIMIZADA: Carrega da memória instantaneamente e atualiza em background
|
||||
Future<void> _loadUserAvatar() async {
|
||||
// 1. LÊ DA MEMÓRIA RÁPIDA PRIMEIRO
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
@@ -84,7 +84,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
final List<Widget> pages = [
|
||||
_buildHomeContent(context),
|
||||
const GamePage(),
|
||||
const TeamsPage(),
|
||||
const TeamsPage(),
|
||||
const StatusPage(),
|
||||
];
|
||||
|
||||
@@ -107,7 +107,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
);
|
||||
_loadUserAvatar();
|
||||
},
|
||||
// 👇 SÓ MOSTRA A IMAGEM OU O BONECO DEPOIS DE LER A MEMÓRIA
|
||||
// SÓ MOSTRA A IMAGEM OU O BONECO DEPOIS DE LER A MEMÓRIA
|
||||
child: !_isMemoryLoaded
|
||||
// Nos primeiros 0.05 segs, mostra só o círculo de fundo (sem boneco)
|
||||
? CircleAvatar(backgroundColor: Colors.white.withOpacity(0.2))
|
||||
@@ -167,8 +167,13 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
return StreamBuilder<List<Map<String, dynamic>>>(
|
||||
stream: _teamController.teamsStream,
|
||||
builder: (context, snapshot) {
|
||||
if (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))));
|
||||
// Correção: Verifica hasData para evitar piscar tela de loading
|
||||
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(
|
||||
@@ -178,11 +183,11 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
final team = teams[index];
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.shield, color: AppTheme.primaryRed),
|
||||
title: Text(team['name'], style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontWeight: FontWeight.bold)),
|
||||
title: Text(team['name'] ?? 'Sem Nome', style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontWeight: FontWeight.bold)),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedTeamId = team['id'].toString();
|
||||
_selectedTeamName = team['name'];
|
||||
_selectedTeamName = team['name'] ?? 'Desconhecido';
|
||||
_teamWins = int.tryParse(team['wins']?.toString() ?? '0') ?? 0;
|
||||
_teamLosses = int.tryParse(team['losses']?.toString() ?? '0') ?? 0;
|
||||
_teamDraws = int.tryParse(team['draws']?.toString() ?? '0') ?? 0;
|
||||
@@ -325,7 +330,11 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
stream: _supabase.from('games').stream(primaryKey: ['id']).order('game_date', ascending: false),
|
||||
builder: (context, gameSnapshot) {
|
||||
if (gameSnapshot.hasError) return Text("Erro: ${gameSnapshot.error}", style: const TextStyle(color: Colors.red));
|
||||
if (gameSnapshot.connectionState == ConnectionState.waiting) return const Center(child: CircularProgressIndicator());
|
||||
|
||||
// Correção: Verifica hasData em vez de ConnectionState para manter a lista na tela enquanto atualiza em plano de fundo
|
||||
if (!gameSnapshot.hasData && gameSnapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
final todosOsJogos = gameSnapshot.data ?? [];
|
||||
final gamesList = todosOsJogos.where((game) {
|
||||
@@ -349,8 +358,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
children: gamesList.map((game) {
|
||||
String dbMyTeam = game['my_team']?.toString() ?? '';
|
||||
String dbOppTeam = game['opponent_team']?.toString() ?? '';
|
||||
int dbMyScore = int.tryParse(game['my_score'].toString()) ?? 0;
|
||||
int dbOppScore = int.tryParse(game['opponent_score'].toString()) ?? 0;
|
||||
int dbMyScore = int.tryParse(game['my_score']?.toString() ?? '0') ?? 0;
|
||||
int dbOppScore = int.tryParse(game['opponent_score']?.toString() ?? '0') ?? 0;
|
||||
|
||||
String opponent; int myScore; int oppScore;
|
||||
|
||||
@@ -389,16 +398,33 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
Map<String, dynamic> _calculateLeaders(List<Map<String, dynamic>> data) {
|
||||
Map<String, int> ptsMap = {}; Map<String, int> astMap = {}; Map<String, int> rbsMap = {}; Map<String, String> namesMap = {};
|
||||
for (var row in data) {
|
||||
String pid = row['member_id'].toString();
|
||||
String pid = row['member_id']?.toString() ?? "unknown";
|
||||
namesMap[pid] = row['player_name']?.toString() ?? "Desconhecido";
|
||||
ptsMap[pid] = (ptsMap[pid] ?? 0) + (int.tryParse(row['pts']?.toString() ?? '0') ?? 0);
|
||||
astMap[pid] = (astMap[pid] ?? 0) + (int.tryParse(row['ast']?.toString() ?? '0') ?? 0);
|
||||
rbsMap[pid] = (rbsMap[pid] ?? 0) + (int.tryParse(row['rbs']?.toString() ?? '0') ?? 0);
|
||||
}
|
||||
if (ptsMap.isEmpty) return {'pts_name': '---', 'pts_val': 0, 'ast_name': '---', 'ast_val': 0, 'rbs_name': '---', 'rbs_val': 0};
|
||||
String getBest(Map<String, int> map) { var bestId = map.entries.reduce((a, b) => a.value > b.value ? a : b).key; return namesMap[bestId]!; }
|
||||
int getBestVal(Map<String, int> map) => map.values.reduce((a, b) => a > b ? a : b);
|
||||
return {'pts_name': getBest(ptsMap), 'pts_val': getBestVal(ptsMap), 'ast_name': getBest(astMap), 'ast_val': getBestVal(astMap), 'rbs_name': getBest(rbsMap), 'rbs_val': getBestVal(rbsMap)};
|
||||
|
||||
if (ptsMap.isEmpty) {
|
||||
return {'pts_name': '---', 'pts_val': 0, 'ast_name': '---', 'ast_val': 0, 'rbs_name': '---', 'rbs_val': 0};
|
||||
}
|
||||
|
||||
String getBest(Map<String, int> map) {
|
||||
if (map.isEmpty) return '---';
|
||||
var bestId = map.entries.reduce((a, b) => a.value > b.value ? a : b).key;
|
||||
return namesMap[bestId] ?? '---';
|
||||
}
|
||||
|
||||
int getBestVal(Map<String, int> map) {
|
||||
if (map.isEmpty) return 0;
|
||||
return map.values.reduce((a, b) => a > b ? a : b);
|
||||
}
|
||||
|
||||
return {
|
||||
'pts_name': getBest(ptsMap), 'pts_val': getBestVal(ptsMap),
|
||||
'ast_name': getBest(astMap), 'ast_val': getBestVal(astMap),
|
||||
'rbs_name': getBest(rbsMap), 'rbs_val': getBestVal(rbsMap)
|
||||
};
|
||||
}
|
||||
|
||||
Widget _buildStatCard({required BuildContext context, required String title, required String playerName, required String statValue, required String statLabel, required Color color, bool isHighlighted = false}) {
|
||||
|
||||
Reference in New Issue
Block a user