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';
|
2023-07-12 15:14:25 +00:00
|
|
|
import 'package:intl/intl.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
import 'package:tetra_stats/data_objects/tetrio.dart';
|
2023-07-12 15:14:25 +00:00
|
|
|
import 'package:tetra_stats/gen/strings.g.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
import 'package:tetra_stats/widgets/tl_thingy.dart';
|
|
|
|
import 'package:tetra_stats/widgets/user_thingy.dart';
|
2023-10-09 18:48:50 +00:00
|
|
|
import 'package:window_manager/window_manager.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
|
2023-07-12 15:14:25 +00:00
|
|
|
final DateFormat dateFormat = DateFormat.yMMMd(LocaleSettings.currentLocale.languageCode).add_Hms();
|
|
|
|
|
2023-06-17 21:50:52 +00:00
|
|
|
class StateView extends StatefulWidget {
|
|
|
|
final TetrioPlayer state;
|
|
|
|
const StateView({Key? key, required this.state}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => StateState();
|
|
|
|
}
|
|
|
|
|
2023-10-09 18:48:50 +00:00
|
|
|
late String oldWindowTitle;
|
|
|
|
|
2023-06-17 21:50:52 +00:00
|
|
|
class StateState extends State<StateView> {
|
|
|
|
late ScrollController _scrollController;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_scrollController = ScrollController();
|
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.stateViewTitle(nickname: widget.state.username.toUpperCase(), date: dateFormat.format(widget.state.state))}");
|
|
|
|
}
|
2023-06-17 21:50:52 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2023-10-09 18:48:50 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_scrollController.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
|
|
|
void _justUpdate() {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
|
|
|
@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.stateViewTitle(nickname: widget.state.username.toUpperCase(), date: dateFormat.format(widget.state.state))),
|
2023-06-17 21:50:52 +00:00
|
|
|
),
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
body: SafeArea(
|
|
|
|
child: NestedScrollView(
|
|
|
|
controller: _scrollController,
|
|
|
|
headerSliverBuilder: (context, value) {
|
|
|
|
return [SliverToBoxAdapter(child: UserThingy(player: widget.state, showStateTimestamp: true, setState: _justUpdate))];
|
|
|
|
},
|
|
|
|
body: TLThingy(tl: widget.state.tlSeason1, userID: widget.state.userId))));
|
|
|
|
}
|
|
|
|
}
|