2023-06-09 21:04:51 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:tetra_stats/data_objects/tetrio.dart';
|
|
|
|
import 'package:tetra_stats/services/tetrio_crud.dart';
|
2023-06-10 21:56:14 +00:00
|
|
|
import 'package:tetra_stats/views/states_view.dart';
|
2023-06-09 21:04:51 +00:00
|
|
|
|
|
|
|
final TetrioService teto = TetrioService();
|
|
|
|
|
2023-06-10 21:56:14 +00:00
|
|
|
class TrackedPlayersView extends StatefulWidget {
|
|
|
|
const TrackedPlayersView({Key? key}) : super(key: key);
|
2023-06-09 21:04:51 +00:00
|
|
|
|
|
|
|
@override
|
2023-06-10 21:56:14 +00:00
|
|
|
State<StatefulWidget> createState() => TrackedPlayersState();
|
2023-06-09 21:04:51 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 21:56:14 +00:00
|
|
|
class TrackedPlayersState extends State<TrackedPlayersView> {
|
2023-06-09 21:04:51 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2023-06-10 21:56:14 +00:00
|
|
|
title: const Text("Stored data"),
|
2023-06-09 21:04:51 +00:00
|
|
|
),
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
body: SafeArea(
|
|
|
|
child: StreamBuilder(
|
|
|
|
stream: teto.allPlayers,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
switch (snapshot.connectionState) {
|
|
|
|
case ConnectionState.none:
|
2023-06-11 21:56:15 +00:00
|
|
|
return const Center(child: Text('none case of StreamBuilder'));
|
2023-06-09 21:04:51 +00:00
|
|
|
case ConnectionState.waiting:
|
|
|
|
case ConnectionState.active:
|
|
|
|
final allPlayers = (snapshot.data != null) ? snapshot.data as Map<String, List<TetrioPlayer>> : <String, List<TetrioPlayer>>{};
|
|
|
|
List<String> keys = allPlayers.keys.toList();
|
|
|
|
return NestedScrollView(
|
|
|
|
headerSliverBuilder: (context, value) {
|
|
|
|
return [
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16),
|
|
|
|
child: Text(
|
2023-06-10 21:56:14 +00:00
|
|
|
'There are ${allPlayers.length} players',
|
2023-06-11 21:56:15 +00:00
|
|
|
style: const TextStyle(color: Colors.white, fontSize: 25),
|
2023-06-09 21:04:51 +00:00
|
|
|
),
|
|
|
|
)),
|
|
|
|
const SliverToBoxAdapter(child: Divider())
|
|
|
|
];
|
|
|
|
},
|
|
|
|
body: ListView.builder(
|
|
|
|
itemCount: allPlayers.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return ListTile(
|
|
|
|
title: Text("${allPlayers[keys[index]]?.last.username}: ${allPlayers[keys[index]]?.length} states"),
|
|
|
|
subtitle: Text("From ${allPlayers[keys[index]]?.first.state} until ${allPlayers[keys[index]]?.last.state}"),
|
2023-06-10 21:56:14 +00:00
|
|
|
trailing: IconButton(
|
|
|
|
icon: const Icon(Icons.delete_forever),
|
|
|
|
onPressed: () {},
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => StatesView(states: allPlayers[keys[index]]!),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2023-06-09 21:04:51 +00:00
|
|
|
);
|
|
|
|
}));
|
|
|
|
case ConnectionState.done:
|
2023-06-11 21:56:15 +00:00
|
|
|
return const Center(
|
2023-06-09 21:04:51 +00:00
|
|
|
child: Text('done case of StreamBuilder',
|
2023-06-11 21:56:15 +00:00
|
|
|
style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: 42), textAlign: TextAlign.center));
|
2023-06-09 21:04:51 +00:00
|
|
|
}
|
|
|
|
})),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|