2023-10-09 18:48:50 +00:00
|
|
|
import 'dart:io';
|
2023-10-10 20:20:27 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:tetra_stats/data_objects/tetrio.dart';
|
2023-07-12 15:14:25 +00:00
|
|
|
import 'package:tetra_stats/gen/strings.g.dart';
|
2024-06-03 23:42:44 +00:00
|
|
|
import 'package:tetra_stats/main.dart' show teto;
|
2023-09-23 19:09:36 +00:00
|
|
|
import 'package:tetra_stats/views/mathes_view.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
import 'package:tetra_stats/views/state_view.dart';
|
2024-06-11 16:30:13 +00:00
|
|
|
import 'package:tetra_stats/widgets/text_timestamp.dart';
|
2023-10-09 18:48:50 +00:00
|
|
|
import 'package:window_manager/window_manager.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
|
|
|
|
class StatesView extends StatefulWidget {
|
|
|
|
final List<TetrioPlayer> states;
|
2024-01-13 18:49:36 +00:00
|
|
|
const StatesView({super.key, required this.states});
|
2023-06-17 21:50:52 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => StatesState();
|
|
|
|
}
|
|
|
|
|
2023-10-09 18:48:50 +00:00
|
|
|
late String oldWindowTitle;
|
|
|
|
|
2023-06-17 21:50:52 +00:00
|
|
|
class StatesState extends State<StatesView> {
|
2023-10-09 18:48:50 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2023-10-10 20:20:27 +00:00
|
|
|
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS){
|
2023-10-09 18:48:50 +00:00
|
|
|
windowManager.getTitle().then((value) => oldWindowTitle = value);
|
|
|
|
windowManager.setTitle("Tetra Stats: ${t.statesViewTitle(number: widget.states.length, nickname: widget.states.last.username.toUpperCase())}");
|
|
|
|
}
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2023-10-10 20:20:27 +00:00
|
|
|
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS) windowManager.setTitle(oldWindowTitle);
|
2023-10-09 18:48:50 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2023-06-17 21:50:52 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-07-12 15:14:25 +00:00
|
|
|
final t = Translations.of(context);
|
2023-06-17 21:50:52 +00:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2023-07-12 15:14:25 +00:00
|
|
|
title: Text(t.statesViewTitle(number: widget.states.length, nickname: widget.states.last.username.toUpperCase())),
|
2023-09-23 19:09:36 +00:00
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: (){
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => MatchesView(userID: widget.states.first.userId, username: widget.states.first.username),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}, icon: const Icon(Icons.list), tooltip: t.viewAllMatches)
|
|
|
|
],
|
2023-06-17 21:50:52 +00:00
|
|
|
),
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
body: SafeArea(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: widget.states.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return ListTile(
|
2024-06-11 16:30:13 +00:00
|
|
|
title: Text(timestamp(widget.states[index].state)),
|
2023-07-12 15:14:25 +00:00
|
|
|
subtitle: Text(t.statesViewEntry(level: widget.states[index].level.toStringAsFixed(2), gameTime: widget.states[index].gameTime, friends: widget.states[index].friendCount, rd: NumberFormat.compact().format(widget.states[index].tlSeason1.rd))),
|
2023-06-17 21:50:52 +00:00
|
|
|
trailing: IconButton(
|
|
|
|
icon: const Icon(Icons.delete_forever),
|
|
|
|
onPressed: () {
|
|
|
|
DateTime nn = widget.states[index].state;
|
|
|
|
teto.deleteState(widget.states[index]).then((value) => setState(() {
|
2024-06-11 16:30:13 +00:00
|
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(t.stateRemoved(date: timestamp(nn)))));
|
2023-06-17 21:50:52 +00:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => StateView(state: widget.states[index]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
}
|