TetraStats/lib/views/states_view.dart

86 lines
3.5 KiB
Dart
Raw Normal View History

import 'dart:io';
2023-10-10 20:20:27 +00:00
import 'package:flutter/foundation.dart';
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';
import 'package:tetra_stats/main.dart' show teto;
import 'package:tetra_stats/views/mathes_view.dart';
import 'package:tetra_stats/views/state_view.dart';
import 'package:window_manager/window_manager.dart';
class StatesView extends StatefulWidget {
final List<TetrioPlayer> states;
const StatesView({super.key, required this.states});
@override
State<StatefulWidget> createState() => StatesState();
}
late String oldWindowTitle;
class StatesState extends State<StatesView> {
@override
void initState() {
2023-10-10 20:20:27 +00:00
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS){
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);
super.dispose();
}
@override
Widget build(BuildContext context) {
2023-07-12 15:14:25 +00:00
final t = Translations.of(context);
final DateFormat dateFormat = DateFormat.yMMMd(LocaleSettings.currentLocale.languageCode).add_Hms();
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())),
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)
],
),
backgroundColor: Colors.black,
body: SafeArea(
child: ListView.builder(
itemCount: widget.states.length,
itemBuilder: (context, index) {
return ListTile(
2023-07-12 15:14:25 +00:00
title: Text(dateFormat.format(widget.states[index].state)),
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))),
trailing: IconButton(
icon: const Icon(Icons.delete_forever),
onPressed: () {
DateTime nn = widget.states[index].state;
teto.deleteState(widget.states[index]).then((value) => setState(() {
2023-07-12 15:14:25 +00:00
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(t.stateRemoved(date: dateFormat.format(nn)))));
}));
},
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => StateView(state: widget.states[index]),
),
);
},
);
})));
}
}