I wonder if it's actually gonna be good
This commit is contained in:
parent
ffad0ae6cb
commit
a9964e7154
|
@ -1,15 +1,16 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:math';
|
||||||
import 'package:tetra_stats/data_objects/tetrio.dart';
|
import 'package:tetra_stats/data_objects/tetrio.dart';
|
||||||
import 'package:tetra_stats/services/tetrio_crud.dart';
|
import 'package:tetra_stats/services/tetrio_crud.dart';
|
||||||
import 'package:tetra_stats/services/sqlite_db_controller.dart';
|
import 'package:tetra_stats/services/sqlite_db_controller.dart';
|
||||||
|
|
||||||
String _searchFor = "";
|
String _searchFor = "";
|
||||||
late TetrioPlayer me;
|
late Future<TetrioPlayer> me;
|
||||||
DB db = DB();
|
DB db = DB();
|
||||||
TetrioService teto = TetrioService();
|
TetrioService teto = TetrioService();
|
||||||
const allowedHeightForPlayerIdInPixels = 60.0;
|
const allowedHeightForPlayerIdInPixels = 40.0;
|
||||||
const allowedHeightForPlayerBioInPixels = 30.0;
|
const allowedHeightForPlayerBioInPixels = 30.0;
|
||||||
const givenTextHeightByScreenPercentage = 0.3;
|
const givenTextHeightByScreenPercentage = 0.3;
|
||||||
|
|
||||||
|
@ -18,38 +19,66 @@ enum SampleItem { itemOne, itemTwo, itemThree }
|
||||||
class MainView extends StatefulWidget {
|
class MainView extends StatefulWidget {
|
||||||
const MainView({Key? key}) : super(key: key);
|
const MainView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
String get title => "Tetra Stats: $_searchFor";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MainView> createState() => _MainViewState();
|
State<MainView> createState() => _MainViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MainViewState extends State<MainView> {
|
Future<TetrioPlayer> fetchTetrioPlayer(String user) async {
|
||||||
Future<TetrioPlayer> fetchTetrioPlayer(String user) async {
|
var url = Uri.https('ch.tetr.io', 'api/users/$user');
|
||||||
var url = Uri.https('ch.tetr.io', 'api/users/$user');
|
final response = await http.get(url);
|
||||||
db.open();
|
// final response = await http.get(Uri.parse('https://ch.tetr.io/'));
|
||||||
final response = await http.get(url);
|
|
||||||
// final response = await http.get(Uri.parse('https://ch.tetr.io/'));
|
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
// If the server did return a 200 OK response,
|
// If the server did return a 200 OK response,
|
||||||
// then parse the JSON.
|
// then parse the JSON.
|
||||||
return TetrioPlayer.fromJson(
|
return TetrioPlayer.fromJson(
|
||||||
jsonDecode(response.body)['data']['user'],
|
jsonDecode(response.body)['data']['user'],
|
||||||
DateTime.fromMillisecondsSinceEpoch(
|
DateTime.fromMillisecondsSinceEpoch(
|
||||||
jsonDecode(response.body)['cache']['cached_at'],
|
jsonDecode(response.body)['cache']['cached_at'],
|
||||||
isUtc: true));
|
isUtc: true));
|
||||||
} else {
|
} else {
|
||||||
// If the server did not return a 200 OK response,
|
// If the server did not return a 200 OK response,
|
||||||
// then throw an exception.
|
// then throw an exception.
|
||||||
throw Exception('Failed to fetch player');
|
throw Exception('Failed to fetch player');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
late Future<TetrioPlayer> me;
|
class _MainViewState extends State<MainView> {
|
||||||
|
bool _searchBoolean = false;
|
||||||
|
String _coverLink = "";
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
me = fetchTetrioPlayer("blaarg");
|
me = fetchTetrioPlayer("dan63047");
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _searchTextField() {
|
||||||
|
return TextField(
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
enabledBorder: UnderlineInputBorder(
|
||||||
|
borderSide: BorderSide(color: Colors.white))),
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
shadows: <Shadow>[
|
||||||
|
Shadow(
|
||||||
|
offset: Offset(0.0, 0.0),
|
||||||
|
blurRadius: 3.0,
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
Shadow(
|
||||||
|
offset: Offset(0.0, 0.0),
|
||||||
|
blurRadius: 8.0,
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onSubmitted: (String value) => setState(() {
|
||||||
|
me = fetchTetrioPlayer(value);
|
||||||
|
_searchFor = value;
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -57,107 +86,97 @@ class _MainViewState extends State<MainView> {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
drawer: NavDrawer(),
|
drawer: NavDrawer(),
|
||||||
backgroundColor: Colors.black,
|
backgroundColor: Colors.black,
|
||||||
body: CustomScrollView(
|
appBar: AppBar(
|
||||||
slivers: [
|
title: !_searchBoolean
|
||||||
SliverAppBar(
|
? Text(
|
||||||
title: const Text("Tetra Stats"),
|
widget.title,
|
||||||
floating: false,
|
style: const TextStyle(
|
||||||
pinned: true,
|
shadows: <Shadow>[
|
||||||
flexibleSpace: Row(
|
Shadow(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
offset: Offset(0.0, 0.0),
|
||||||
children: [
|
blurRadius: 3.0,
|
||||||
ClipRRect(
|
color: Colors.black,
|
||||||
borderRadius: BorderRadius.circular(1000),
|
),
|
||||||
child: Image.network(
|
Shadow(
|
||||||
"https://tetr.io/user-content/avatars/6098518e3d5155e6ec429cdc.jpg?rv=1673453211638",
|
offset: Offset(0.0, 0.0),
|
||||||
fit: BoxFit.fitHeight,
|
blurRadius: 8.0,
|
||||||
height: 256,
|
color: Colors.black,
|
||||||
),
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
LayoutBuilder(builder: (context, constraints) {
|
)
|
||||||
return Column(
|
: _searchTextField(),
|
||||||
mainAxisSize: MainAxisSize.min,
|
flexibleSpace: Image.network(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
_coverLink,
|
||||||
children: [
|
fit: BoxFit.cover,
|
||||||
if (constraints.maxHeight *
|
),
|
||||||
givenTextHeightByScreenPercentage >
|
backgroundColor: Colors.black,
|
||||||
allowedHeightForPlayerBioInPixels)
|
actions: [
|
||||||
const Text("dan63047",
|
!_searchBoolean
|
||||||
style: TextStyle(
|
? IconButton(
|
||||||
fontFamily: "Eurostile Round Extended",
|
onPressed: () {
|
||||||
color: Colors.white,
|
setState(() {
|
||||||
fontSize: 42))
|
//add
|
||||||
else
|
_searchBoolean = true;
|
||||||
const Text("dan63047",
|
});
|
||||||
style: TextStyle(
|
},
|
||||||
fontFamily: "Eurostile Round Extended",
|
icon: const Icon(Icons.search),
|
||||||
color: Colors.white,
|
tooltip: "Search player",
|
||||||
fontSize: 36)),
|
)
|
||||||
if (constraints.maxHeight *
|
: IconButton(
|
||||||
givenTextHeightByScreenPercentage >
|
onPressed: () {
|
||||||
allowedHeightForPlayerIdInPixels)
|
setState(() {
|
||||||
const Text(
|
//add
|
||||||
"6098518e3d5155e6ec429cdc",
|
_searchBoolean = false;
|
||||||
style: TextStyle(
|
});
|
||||||
fontFamily: "Eurostile Round Condensed",
|
},
|
||||||
color: Colors.white,
|
icon: const Icon(Icons.clear),
|
||||||
fontSize: 14),
|
tooltip: "Close search",
|
||||||
),
|
),
|
||||||
if (constraints.maxHeight *
|
PopupMenuButton(
|
||||||
givenTextHeightByScreenPercentage >
|
itemBuilder: (BuildContext context) => <PopupMenuEntry<SampleItem>>[
|
||||||
allowedHeightForPlayerBioInPixels)
|
const PopupMenuItem<SampleItem>(
|
||||||
const Text(
|
value: SampleItem.itemOne,
|
||||||
"osk, please, if my supporter ends, let me use :petthekagari: in the chat",
|
child: Text('Compare'),
|
||||||
style: TextStyle(
|
|
||||||
fontFamily: "Eurostile Round",
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 16,
|
|
||||||
),
|
|
||||||
softWrap: true),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
})
|
|
||||||
],
|
|
||||||
),
|
|
||||||
expandedHeight: 400,
|
|
||||||
backgroundColor: Colors.black,
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
onPressed: () {},
|
|
||||||
icon: const Icon(Icons.search),
|
|
||||||
tooltip: "Search player",
|
|
||||||
),
|
),
|
||||||
PopupMenuButton(
|
const PopupMenuItem<SampleItem>(
|
||||||
itemBuilder: (BuildContext context) =>
|
value: SampleItem.itemTwo,
|
||||||
<PopupMenuEntry<SampleItem>>[
|
child: Text('States'),
|
||||||
const PopupMenuItem<SampleItem>(
|
),
|
||||||
value: SampleItem.itemOne,
|
const PopupMenuItem<SampleItem>(
|
||||||
child: Text('Item 1'),
|
value: SampleItem.itemThree,
|
||||||
),
|
child: Text('Settings'),
|
||||||
const PopupMenuItem<SampleItem>(
|
|
||||||
value: SampleItem.itemTwo,
|
|
||||||
child: Text('Item 2'),
|
|
||||||
),
|
|
||||||
const PopupMenuItem<SampleItem>(
|
|
||||||
value: SampleItem.itemThree,
|
|
||||||
child: Text('Item 3'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
SliverList(
|
|
||||||
delegate: SliverChildBuilderDelegate(
|
|
||||||
(context, index) => ListTile(
|
|
||||||
title: Text('Item #$index'),
|
|
||||||
tileColor: Colors.transparent,
|
|
||||||
textColor: Colors.white,
|
|
||||||
),
|
|
||||||
childCount: 1000,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
body: SafeArea(
|
||||||
|
child: FutureBuilder<TetrioPlayer>(
|
||||||
|
future: me,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
_coverLink =
|
||||||
|
"https://tetr.io/user-content/banners/${snapshot.data!.userId}.jpg?rv=${snapshot.data!.bannerRevision}";
|
||||||
|
return ListView(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
children: [
|
||||||
|
_UserThingy(player: snapshot.data!),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else if (snapshot.hasError) {
|
||||||
|
return Text('${snapshot.error}',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: "Eurostile Round Extended",
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 42));
|
||||||
|
}
|
||||||
|
|
||||||
|
// By default, show a loading spinner.
|
||||||
|
return const CircularProgressIndicator();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,16 +189,10 @@ class NavDrawer extends StatelessWidget {
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
const DrawerHeader(
|
const DrawerHeader(
|
||||||
child: Text(
|
child: Text(
|
||||||
'Side menu',
|
'Side menu',
|
||||||
style: TextStyle(color: Colors.white, fontSize: 25),
|
style: TextStyle(color: Colors.white, fontSize: 25),
|
||||||
),
|
)),
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Color.fromARGB(255, 40, 44, 41),
|
|
||||||
image: DecorationImage(
|
|
||||||
fit: BoxFit.fill,
|
|
||||||
image: AssetImage('assets/images/cover.jpg'))),
|
|
||||||
),
|
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.input),
|
leading: const Icon(Icons.input),
|
||||||
title: const Text('Welcome'),
|
title: const Text('Welcome'),
|
||||||
|
@ -260,3 +273,145 @@ class NavDrawer extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _UserThingy extends StatelessWidget {
|
||||||
|
final TetrioPlayer player;
|
||||||
|
const _UserThingy({Key? key, required this.player}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return LayoutBuilder(builder: (context, constraints) {
|
||||||
|
final settings = context
|
||||||
|
.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>();
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Flex(
|
||||||
|
direction: Axis.vertical,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(1000),
|
||||||
|
child: Image.network(
|
||||||
|
"https://tetr.io/user-content/avatars/${player.userId}.jpg?rv=${player.avatarRevision}",
|
||||||
|
fit: BoxFit.fitHeight,
|
||||||
|
height: 128,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Flexible(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Text(player.username,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: "Eurostile Round Extended",
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 42)),
|
||||||
|
Text(
|
||||||
|
player.userId,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: "Eurostile Round Condensed",
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 14),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Wrap(
|
||||||
|
direction: Axis.horizontal,
|
||||||
|
alignment: WrapAlignment.center,
|
||||||
|
spacing: 25,
|
||||||
|
crossAxisAlignment: WrapCrossAlignment.start,
|
||||||
|
clipBehavior: Clip.hardEdge, // hard WHAT???
|
||||||
|
children: [
|
||||||
|
_StatCellNum(
|
||||||
|
playerStat: player.level,
|
||||||
|
playerStatLabel: "Level\n${player.xp.floor().toString()} XP"),
|
||||||
|
_StatCellDuration(
|
||||||
|
playerStat: player.gameTime, playerStatLabel: "Gametime"),
|
||||||
|
_StatCellNum(
|
||||||
|
playerStat: player.gamesPlayed,
|
||||||
|
playerStatLabel: "Games\nPlayed"),
|
||||||
|
_StatCellNum(
|
||||||
|
playerStat: player.gamesWon, playerStatLabel: "Games\nWon"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StatCellNum extends StatelessWidget {
|
||||||
|
const _StatCellNum({
|
||||||
|
super.key,
|
||||||
|
required this.playerStat,
|
||||||
|
required this.playerStatLabel,
|
||||||
|
});
|
||||||
|
|
||||||
|
final num playerStat;
|
||||||
|
final String playerStatLabel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
playerStat.toStringAsFixed(0),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: "Eurostile Round Extended",
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 32,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
playerStatLabel,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: "Eurostile Round",
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StatCellDuration extends StatelessWidget {
|
||||||
|
const _StatCellDuration({
|
||||||
|
super.key,
|
||||||
|
required this.playerStat,
|
||||||
|
required this.playerStatLabel,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Duration playerStat;
|
||||||
|
final String playerStatLabel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
playerStat.toString().toString().split('.').first.padLeft(8, "0"),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: "Eurostile Round Extended",
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 32,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
playerStatLabel,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: "Eurostile Round",
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue