128 lines
No EOL
6 KiB
Dart
128 lines
No EOL
6 KiB
Dart
// ===========================================================================
|
|
// FILE: lib/ui/admin/admin_screen.dart
|
|
// ===========================================================================
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../../core/theme_manager.dart';
|
|
|
|
class AdminScreen extends StatelessWidget {
|
|
const AdminScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = context.watch<ThemeManager>().currentColors;
|
|
|
|
return Scaffold(
|
|
backgroundColor: theme.background,
|
|
appBar: AppBar(
|
|
title: Text("DASHBOARD ADMIN 🕵️♂️", style: TextStyle(color: theme.text, fontWeight: FontWeight.w900, letterSpacing: 2)),
|
|
backgroundColor: theme.background,
|
|
iconTheme: IconThemeData(color: theme.text),
|
|
elevation: 0,
|
|
),
|
|
body: StreamBuilder<QuerySnapshot>(
|
|
// Ordiniamo per Ultimo Accesso, così i giocatori attivi di recente sono in cima!
|
|
stream: FirebaseFirestore.instance.collection('leaderboard').orderBy('lastActive', descending: true).snapshots(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return Center(child: CircularProgressIndicator(color: theme.playerBlue));
|
|
}
|
|
if (!snapshot.hasData || snapshot.data!.docs.isEmpty) {
|
|
return Center(child: Text("Nessun giocatore trovato nel database.", style: TextStyle(color: theme.text)));
|
|
}
|
|
|
|
var docs = snapshot.data!.docs;
|
|
|
|
return ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: docs.length,
|
|
itemBuilder: (context, index) {
|
|
var data = docs[index].data() as Map<String, dynamic>;
|
|
|
|
String name = data['name'] ?? 'Fantasma';
|
|
int level = data['level'] ?? 1;
|
|
int xp = data['xp'] ?? 0;
|
|
int wins = data['wins'] ?? 0;
|
|
String platform = data['platform'] ?? 'Sconosciuta';
|
|
|
|
// Formattazione Date (Se esistono)
|
|
DateTime? created;
|
|
if (data['accountCreated'] != null) created = (data['accountCreated'] as Timestamp).toDate();
|
|
|
|
DateTime? lastActive;
|
|
if (data['lastActive'] != null) lastActive = (data['lastActive'] as Timestamp).toDate();
|
|
|
|
String createdStr = created != null ? DateFormat('dd MMM yyyy').format(created) : 'N/D';
|
|
String lastActiveStr = lastActive != null ? DateFormat('dd MMM yyyy - HH:mm').format(lastActive) : 'N/D';
|
|
|
|
IconData platformIcon = Icons.device_unknown;
|
|
if (platform == 'iOS') platformIcon = Icons.apple;
|
|
if (platform == 'Android') platformIcon = Icons.android;
|
|
|
|
return Card(
|
|
color: theme.text.withOpacity(0.05),
|
|
elevation: 0,
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(15),
|
|
side: BorderSide(color: theme.gridLine.withOpacity(0.3))
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(name, style: TextStyle(color: theme.playerBlue, fontSize: 22, fontWeight: FontWeight.w900)),
|
|
Icon(platformIcon, color: theme.text.withOpacity(0.7)),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
Text("Liv. $level", style: TextStyle(color: theme.playerRed, fontWeight: FontWeight.bold, fontSize: 16)),
|
|
const SizedBox(width: 15),
|
|
Text("$xp XP", style: TextStyle(color: theme.text.withOpacity(0.7))),
|
|
const SizedBox(width: 15),
|
|
Text("Vittorie: $wins", style: TextStyle(color: Colors.amber.shade700, fontWeight: FontWeight.bold)),
|
|
],
|
|
),
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 8.0),
|
|
child: Divider(),
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text("Registrato il:", style: TextStyle(color: theme.text.withOpacity(0.5), fontSize: 10)),
|
|
Text(createdStr, style: TextStyle(color: theme.text, fontSize: 12, fontWeight: FontWeight.bold)),
|
|
],
|
|
),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Text("Ultimo Accesso:", style: TextStyle(color: theme.text.withOpacity(0.5), fontSize: 10)),
|
|
Text(lastActiveStr, style: TextStyle(color: Colors.green, fontSize: 12, fontWeight: FontWeight.bold)),
|
|
],
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
),
|
|
);
|
|
}
|
|
} |