some shit happening idk
This commit is contained in:
parent
6625c5efbc
commit
5feadcfe09
|
@ -1,4 +1,27 @@
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
Future<TetrioPlayer> fetchTetrioRecords(String user) async {
|
||||||
|
var url = Uri.https('ch.tetr.io', 'api/users/$user/records');
|
||||||
|
final response = await http.get(url);
|
||||||
|
// final response = await http.get(Uri.parse('https://ch.tetr.io/'));
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
// If the server did return a 200 OK response,
|
||||||
|
// then parse the JSON.
|
||||||
|
return TetrioPlayer.fromJson(jsonDecode(response.body));
|
||||||
|
} else {
|
||||||
|
// If the server did not return a 200 OK response,
|
||||||
|
// then throw an exception.
|
||||||
|
throw Exception('Failed to fetch player');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Duration doubleSecondsToDuration(double value) {
|
||||||
|
value = value * 1000000;
|
||||||
|
return Duration(microseconds: value.floor());
|
||||||
|
}
|
||||||
|
|
||||||
class TetrioPlayer {
|
class TetrioPlayer {
|
||||||
String? userId;
|
String? userId;
|
||||||
|
@ -13,7 +36,7 @@ class TetrioPlayer {
|
||||||
int? friendCount;
|
int? friendCount;
|
||||||
int? gamesPlayed;
|
int? gamesPlayed;
|
||||||
int? gamesWon;
|
int? gamesWon;
|
||||||
double? gameTime;
|
Duration? gameTime;
|
||||||
double? xp;
|
double? xp;
|
||||||
int? supporterTier;
|
int? supporterTier;
|
||||||
bool? verified;
|
bool? verified;
|
||||||
|
@ -52,35 +75,56 @@ class TetrioPlayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
TetrioPlayer.fromJson(Map<String, dynamic> json) {
|
TetrioPlayer.fromJson(Map<String, dynamic> json) {
|
||||||
userId = json['data']['user']['_id'];
|
userId = json['_id'];
|
||||||
username = json['data']['user']['username'];
|
username = json['username'];
|
||||||
role = json['data']['user']['role'];
|
role = json['role'];
|
||||||
registrationTime = json['data']['user']['ts'] != null
|
registrationTime = json['ts'] != null ? DateTime.parse(json['ts']) : null;
|
||||||
? DateTime.parse(json['data']['user']['ts'])
|
if (json['badges'] != null) {
|
||||||
: null;
|
|
||||||
if (json['data']['user']['badges'] != null) {
|
|
||||||
badges = <Badge>[];
|
badges = <Badge>[];
|
||||||
json['data']['user']['badges'].forEach((v) {
|
json['badges'].forEach((v) {
|
||||||
badges!.add(Badge.fromJson(v));
|
badges!.add(Badge.fromJson(v));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
xp = json['data']['user']['xp'].toDouble();
|
xp = json['xp'].toDouble();
|
||||||
gamesPlayed = json['data']['user']['gamesplayed'];
|
gamesPlayed = json['gamesplayed'];
|
||||||
gamesWon = json['data']['user']['gameswon'];
|
gamesWon = json['gameswon'];
|
||||||
gameTime = json['data']['user']['gametime'].toDouble();
|
gameTime = doubleSecondsToDuration(json['gametime'].toDouble());
|
||||||
country = json['data']['user']['country'];
|
country = json['country'];
|
||||||
supporterTier = json['data']['user']['supporter_tier'];
|
supporterTier = json['supporter_tier'];
|
||||||
verified = json['data']['user']['verified'];
|
verified = json['verified'];
|
||||||
tlSeason1 = json['data']['user']['league'] != null
|
tlSeason1 = json['league'] != null
|
||||||
? TetraLeagueAlpha.fromJson(json['data']['user']['league'])
|
? TetraLeagueAlpha.fromJson(json['league'])
|
||||||
: null;
|
: null;
|
||||||
avatarRevision = json['data']['user']['avatar_revision'];
|
avatarRevision = json['avatar_revision'];
|
||||||
bannerRevision = json['data']['user']['banner_revision'];
|
bannerRevision = json['banner_revision'];
|
||||||
bio = json['data']['user']['bio'];
|
bio = json['bio'];
|
||||||
connections = json['data']['user']['connections'] != null
|
connections = json['connections'] != null
|
||||||
? Connections.fromJson(json['data']['user']['connections'])
|
? Connections.fromJson(json['connections'])
|
||||||
: null;
|
: null;
|
||||||
friendCount = json['data']['user']['friend_count'];
|
var url = Uri.https('ch.tetr.io', 'api/users/$userId/records');
|
||||||
|
Future response = http.get(url);
|
||||||
|
response.then((value) {
|
||||||
|
if (value.statusCode == 200) {
|
||||||
|
sprint = jsonDecode(value.body)['data']['records']['40l']['record'] !=
|
||||||
|
null
|
||||||
|
? [
|
||||||
|
RecordSingle.fromJson(
|
||||||
|
jsonDecode(value.body)['data']['records']['40l']['record'])
|
||||||
|
]
|
||||||
|
: null;
|
||||||
|
blitz =
|
||||||
|
jsonDecode(value.body)['data']['records']['blitz']['record'] != null
|
||||||
|
? [
|
||||||
|
RecordSingle.fromJson(jsonDecode(value.body)['data']
|
||||||
|
['records']['blitz']['record'])
|
||||||
|
]
|
||||||
|
: null;
|
||||||
|
zen = TetrioZen.fromJson(jsonDecode(value.body)['data']['zen']);
|
||||||
|
} else {
|
||||||
|
throw Exception('Failed to fetch player');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
friendCount = json['friend_count'];
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
|
@ -271,7 +315,7 @@ class EndContextSingle {
|
||||||
int? lines;
|
int? lines;
|
||||||
int? score;
|
int? score;
|
||||||
int? seed;
|
int? seed;
|
||||||
double? finalTime;
|
Duration? finalTime;
|
||||||
int? tSpins;
|
int? tSpins;
|
||||||
Clears? clears;
|
Clears? clears;
|
||||||
Finesse? finesse;
|
Finesse? finesse;
|
||||||
|
@ -297,7 +341,7 @@ class EndContextSingle {
|
||||||
lines = json['lines'];
|
lines = json['lines'];
|
||||||
inputs = json['inputs'];
|
inputs = json['inputs'];
|
||||||
holds = json['holds'];
|
holds = json['holds'];
|
||||||
finalTime = json['finalTime'];
|
finalTime = doubleSecondsToDuration(json['finalTime'].toDouble());
|
||||||
score = json['score'];
|
score = json['score'];
|
||||||
level = json['level'];
|
level = json['level'];
|
||||||
topCombo = json['topcombo'];
|
topCombo = json['topcombo'];
|
||||||
|
@ -554,7 +598,7 @@ class RecordSingle {
|
||||||
? EndContextSingle.fromJson(json['endcontext'])
|
? EndContextSingle.fromJson(json['endcontext'])
|
||||||
: null;
|
: null;
|
||||||
replayId = json['replayid'];
|
replayId = json['replayid'];
|
||||||
timestamp = json['ts'];
|
timestamp = DateTime.parse(json['ts']);
|
||||||
userId = json['user']['_id'];
|
userId = json['user']['_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class _MainViewState extends State<MainView> {
|
||||||
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(jsonDecode(response.body));
|
return TetrioPlayer.fromJson(jsonDecode(response.body)['data']['user']);
|
||||||
} 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.
|
||||||
|
@ -52,6 +52,11 @@ class _MainViewState extends State<MainView> {
|
||||||
onChanged: (String value) {
|
onChanged: (String value) {
|
||||||
_searchFor = value;
|
_searchFor = value;
|
||||||
},
|
},
|
||||||
|
onSubmitted: (String value) {
|
||||||
|
setState(() {
|
||||||
|
me = fetchTetrioPlayer(value);
|
||||||
|
});
|
||||||
|
},
|
||||||
maxLength: 25,
|
maxLength: 25,
|
||||||
)),
|
)),
|
||||||
TextButton(
|
TextButton(
|
||||||
|
@ -65,15 +70,37 @@ class _MainViewState extends State<MainView> {
|
||||||
future: me,
|
future: me,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
return Column(children: [
|
return Flexible(
|
||||||
|
child: Column(children: [
|
||||||
Text(snapshot.data!.username.toString()),
|
Text(snapshot.data!.username.toString()),
|
||||||
Text("Level ${snapshot.data!.getLevel()}"),
|
Text(snapshot.data!.userId.toString()),
|
||||||
Text("Registered ${snapshot.data!.registrationTime}"),
|
Text(snapshot.data!.role.toString()),
|
||||||
Text("${snapshot.data!.tlSeason1!.rating} TR"),
|
|
||||||
Text(
|
Text(
|
||||||
"${snapshot.data!.tlSeason1!.glicko}±${snapshot.data!.tlSeason1!.rd} GLICKO"),
|
"Level ${snapshot.data!.getLevel().toStringAsFixed(2)} (${snapshot.data!.xp} XP)"),
|
||||||
Text("${snapshot.data!.zen}")
|
Text("Registered ${snapshot.data!.registrationTime}"),
|
||||||
]);
|
Text("Bio: ${snapshot.data!.bio}", softWrap: true),
|
||||||
|
Text("Country: ${snapshot.data!.country}"),
|
||||||
|
Text("${snapshot.data!.friendCount} friends"),
|
||||||
|
Text(
|
||||||
|
"Won/PLayed: ${snapshot.data!.gamesWon}/${snapshot.data!.gamesPlayed}"),
|
||||||
|
Text("Gametime: ${snapshot.data!.gameTime}"),
|
||||||
|
Text("Supporter tier ${snapshot.data!.supporterTier}"),
|
||||||
|
const Text("\nTetra League", softWrap: true),
|
||||||
|
Text(
|
||||||
|
"${snapshot.data!.tlSeason1!.rating?.toStringAsFixed(2)} TR"),
|
||||||
|
Text(
|
||||||
|
"${snapshot.data!.tlSeason1!.glicko?.toStringAsFixed(2)}±${snapshot.data!.tlSeason1!.rd?.toStringAsFixed(2)} GLICKO"),
|
||||||
|
Text(
|
||||||
|
"Rank: ${snapshot.data!.tlSeason1!.rank?.toUpperCase()} (top ${(snapshot.data!.tlSeason1!.percentile! * 100).toStringAsFixed(2)}%)"),
|
||||||
|
Text(
|
||||||
|
"Won/Games: ${snapshot.data!.tlSeason1!.gamesPlayed}/${snapshot.data!.tlSeason1!.gamesWon}"),
|
||||||
|
Text(
|
||||||
|
"№${snapshot.data!.tlSeason1!.standing} (№${snapshot.data!.tlSeason1!.standingLocal} in country)"),
|
||||||
|
Text(
|
||||||
|
"${snapshot.data!.tlSeason1!.apm} APM, ${snapshot.data!.tlSeason1!.pps} PPS, ${snapshot.data!.tlSeason1!.vs} VS"),
|
||||||
|
const Text("\n40 Lines", softWrap: true),
|
||||||
|
Text(snapshot.data!.sprint.toString()),
|
||||||
|
]));
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
return Text('${snapshot.error}');
|
return Text('${snapshot.error}');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue