Thinking about animations...
This commit is contained in:
parent
500639df05
commit
6b84e67f33
|
@ -42,6 +42,8 @@ import 'package:tetra_stats/widgets/tl_progress_bar.dart';
|
|||
import 'package:tetra_stats/widgets/user_thingy.dart';
|
||||
|
||||
var fDiff = NumberFormat("+#,###.####;-#,###.####");
|
||||
late Future<FetchResults> _data;
|
||||
late Future<News> _newsData;
|
||||
|
||||
class MainView extends StatefulWidget {
|
||||
final String? player;
|
||||
|
@ -78,12 +80,44 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
|
|||
void initState() {
|
||||
teto.open();
|
||||
controller = ScrollController();
|
||||
changePlayer(_searchFor);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
Future<FetchResults> _getData() async {
|
||||
TetrioPlayer player;
|
||||
try{
|
||||
if (_searchFor.startsWith("ds:")){
|
||||
player = await teto.fetchPlayer(_searchFor.substring(3), isItDiscordID: true); // we trying to get him with that
|
||||
}else{
|
||||
player = await teto.fetchPlayer(_searchFor); // Otherwise it's probably a user id or username
|
||||
}
|
||||
}on TetrioPlayerNotExist{
|
||||
return FetchResults(false, null, [], null, null, TetrioPlayerNotExist());
|
||||
}
|
||||
late Summaries summaries;
|
||||
late Cutoffs cutoffs;
|
||||
List<dynamic> requests = await Future.wait([
|
||||
teto.fetchSummaries(player.userId),
|
||||
teto.fetchCutoffsBeanserver(),
|
||||
]);
|
||||
List<TetraLeague> states = await teto.getStates(player.userId, season: currentSeason);
|
||||
summaries = requests[0];
|
||||
cutoffs = requests[1];
|
||||
|
||||
bool isTracking = await teto.isPlayerTracking(player.userId);
|
||||
if (isTracking){ // if tracked - save data to local DB
|
||||
await teto.storeState(summaries.league);
|
||||
}
|
||||
|
||||
return FetchResults(true, player, states, summaries, cutoffs, null);
|
||||
}
|
||||
|
||||
void changePlayer(String player) {
|
||||
setState(() {
|
||||
_searchFor = player;
|
||||
_data = _getData();
|
||||
_newsData = teto.fetchNews(_searchFor);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -114,7 +148,8 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
|
|||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
NavigationRail(
|
||||
TweenAnimationBuilder(
|
||||
child: NavigationRail(
|
||||
leading: FloatingActionButton(
|
||||
elevation: 0,
|
||||
onPressed: () {
|
||||
|
@ -144,6 +179,16 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
|
|||
});
|
||||
},
|
||||
),
|
||||
duration: Durations.long4,
|
||||
tween: Tween<double>(begin: 0, end: 1),
|
||||
curve: Easing.emphasizedDecelerate,
|
||||
builder: (context, value, child) {
|
||||
return Container(
|
||||
transform: Matrix4.translationValues(-80+value*80, 0, 0),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: switch (destination){
|
||||
0 => DestinationHome(searchFor: _searchFor, constraints: constraints),
|
||||
|
@ -691,7 +736,7 @@ class LeagueCard extends StatelessWidget{
|
|||
|
||||
}
|
||||
|
||||
class _DestinationHomeState extends State<DestinationHome> {
|
||||
class _DestinationHomeState extends State<DestinationHome> with SingleTickerProviderStateMixin {
|
||||
Cards rightCard = Cards.overview;
|
||||
CardMod cardMod = CardMod.info;
|
||||
//Duration postSeasonLeft = seasonStart.difference(DateTime.now());
|
||||
|
@ -700,38 +745,10 @@ class _DestinationHomeState extends State<DestinationHome> {
|
|||
late bool blitzBetterThanClosestAverage;
|
||||
late MapEntry? closestAverageSprint;
|
||||
late bool sprintBetterThanClosestAverage;
|
||||
late AnimationController _transition;
|
||||
bool? sprintBetterThanRankAverage;
|
||||
bool? blitzBetterThanRankAverage;
|
||||
|
||||
Future<FetchResults> _getData() async {
|
||||
TetrioPlayer player;
|
||||
try{
|
||||
if (widget.searchFor.startsWith("ds:")){
|
||||
player = await teto.fetchPlayer(widget.searchFor.substring(3), isItDiscordID: true); // we trying to get him with that
|
||||
}else{
|
||||
player = await teto.fetchPlayer(widget.searchFor); // Otherwise it's probably a user id or username
|
||||
}
|
||||
}on TetrioPlayerNotExist{
|
||||
return FetchResults(false, null, [], null, null, TetrioPlayerNotExist());
|
||||
}
|
||||
late Summaries summaries;
|
||||
late Cutoffs cutoffs;
|
||||
List<dynamic> requests = await Future.wait([
|
||||
teto.fetchSummaries(player.userId),
|
||||
teto.fetchCutoffsBeanserver(),
|
||||
]);
|
||||
List<TetraLeague> states = await teto.getStates(player.userId, season: currentSeason);
|
||||
summaries = requests[0];
|
||||
cutoffs = requests[1];
|
||||
|
||||
bool isTracking = await teto.isPlayerTracking(player.userId);
|
||||
if (isTracking){ // if tracked - save data to local DB
|
||||
await teto.storeState(summaries.league);
|
||||
}
|
||||
|
||||
return FetchResults(true, player, states, summaries, cutoffs, null);
|
||||
}
|
||||
|
||||
Widget getOverviewCard(Summaries summaries){
|
||||
return Column(
|
||||
children: [
|
||||
|
@ -1537,13 +1554,22 @@ class _DestinationHomeState extends State<DestinationHome> {
|
|||
)
|
||||
]
|
||||
};
|
||||
|
||||
_transition = AnimationController(vsync: this, value: 0, duration: Durations.long4);
|
||||
|
||||
_transition.addListener((){
|
||||
setState(() {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<FetchResults>(
|
||||
future: _getData(),
|
||||
future: _data,
|
||||
builder: (context, snapshot) {
|
||||
switch (snapshot.connectionState){
|
||||
case ConnectionState.none:
|
||||
|
@ -1576,7 +1602,17 @@ class _DestinationHomeState extends State<DestinationHome> {
|
|||
closestAverageBlitz = blitzAverages.entries.singleWhere((element) => element.value == blitzAverages.values.reduce((a, b) => (a-snapshot.data!.summaries!.blitz!.stats.score).abs() < (b -snapshot.data!.summaries!.blitz!.stats.score).abs() ? a : b));
|
||||
blitzBetterThanClosestAverage = snapshot.data!.summaries!.blitz!.stats.score > closestAverageBlitz!.value;
|
||||
}
|
||||
return Row(
|
||||
return TweenAnimationBuilder(
|
||||
duration: Durations.long4,
|
||||
tween: Tween<double>(begin: 0, end: 1),
|
||||
curve: Easing.emphasizedDecelerate,
|
||||
builder: (context, value, child) {
|
||||
return Container(
|
||||
transform: Matrix4.translationValues(0, 600-value*600, 0),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 450,
|
||||
|
@ -1608,7 +1644,7 @@ class _DestinationHomeState extends State<DestinationHome> {
|
|||
//if (testNews != null && testNews!.news.isNotEmpty)
|
||||
Expanded(
|
||||
child: FutureBuilder<News>(
|
||||
future: teto.fetchNews(widget.searchFor),
|
||||
future: _newsData,
|
||||
builder: (context, snapshot) {
|
||||
switch (snapshot.connectionState){
|
||||
case ConnectionState.none:
|
||||
|
@ -1640,6 +1676,21 @@ class _DestinationHomeState extends State<DestinationHome> {
|
|||
SizedBox(
|
||||
height: rightCard != Cards.overview ? widget.constraints.maxHeight - 64 : widget.constraints.maxHeight - 32,
|
||||
child: SingleChildScrollView(
|
||||
child: DualTransitionBuilder(
|
||||
animation: _transition,
|
||||
forwardBuilder: (context, animation, child){
|
||||
print(animation);
|
||||
return Container(
|
||||
transform: Matrix4.translationValues(600-animation.value*600, 0, 0),
|
||||
child: child!
|
||||
);
|
||||
},
|
||||
reverseBuilder: (context, animation, child){
|
||||
return Container(
|
||||
transform: Matrix4.translationValues(-600+animation.value*600, 0, 0),
|
||||
child: child!
|
||||
);
|
||||
},
|
||||
child: switch (rightCard){
|
||||
Cards.overview => getOverviewCard(snapshot.data!.summaries!),
|
||||
Cards.tetraLeague => switch (cardMod){
|
||||
|
@ -1667,6 +1718,7 @@ class _DestinationHomeState extends State<DestinationHome> {
|
|||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
if (modeButtons[rightCard]!.length > 1) SegmentedButton<CardMod>(
|
||||
showSelectedIcon: false,
|
||||
selected: <CardMod>{cardMod},
|
||||
|
@ -1674,6 +1726,7 @@ class _DestinationHomeState extends State<DestinationHome> {
|
|||
onSelectionChanged: (p0) {
|
||||
setState(() {
|
||||
cardMod = p0.first;
|
||||
//_transition.;
|
||||
});
|
||||
},
|
||||
),
|
||||
|
@ -1711,6 +1764,7 @@ class _DestinationHomeState extends State<DestinationHome> {
|
|||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue