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';
|
import 'package:tetra_stats/widgets/user_thingy.dart';
|
||||||
|
|
||||||
var fDiff = NumberFormat("+#,###.####;-#,###.####");
|
var fDiff = NumberFormat("+#,###.####;-#,###.####");
|
||||||
|
late Future<FetchResults> _data;
|
||||||
|
late Future<News> _newsData;
|
||||||
|
|
||||||
class MainView extends StatefulWidget {
|
class MainView extends StatefulWidget {
|
||||||
final String? player;
|
final String? player;
|
||||||
|
@ -78,12 +80,44 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
|
||||||
void initState() {
|
void initState() {
|
||||||
teto.open();
|
teto.open();
|
||||||
controller = ScrollController();
|
controller = ScrollController();
|
||||||
|
changePlayer(_searchFor);
|
||||||
super.initState();
|
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) {
|
void changePlayer(String player) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_searchFor = player;
|
_searchFor = player;
|
||||||
|
_data = _getData();
|
||||||
|
_newsData = teto.fetchNews(_searchFor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +148,8 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
NavigationRail(
|
TweenAnimationBuilder(
|
||||||
|
child: NavigationRail(
|
||||||
leading: FloatingActionButton(
|
leading: FloatingActionButton(
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
onPressed: () {
|
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(
|
Expanded(
|
||||||
child: switch (destination){
|
child: switch (destination){
|
||||||
0 => DestinationHome(searchFor: _searchFor, constraints: constraints),
|
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;
|
Cards rightCard = Cards.overview;
|
||||||
CardMod cardMod = CardMod.info;
|
CardMod cardMod = CardMod.info;
|
||||||
//Duration postSeasonLeft = seasonStart.difference(DateTime.now());
|
//Duration postSeasonLeft = seasonStart.difference(DateTime.now());
|
||||||
|
@ -700,38 +745,10 @@ class _DestinationHomeState extends State<DestinationHome> {
|
||||||
late bool blitzBetterThanClosestAverage;
|
late bool blitzBetterThanClosestAverage;
|
||||||
late MapEntry? closestAverageSprint;
|
late MapEntry? closestAverageSprint;
|
||||||
late bool sprintBetterThanClosestAverage;
|
late bool sprintBetterThanClosestAverage;
|
||||||
|
late AnimationController _transition;
|
||||||
bool? sprintBetterThanRankAverage;
|
bool? sprintBetterThanRankAverage;
|
||||||
bool? blitzBetterThanRankAverage;
|
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){
|
Widget getOverviewCard(Summaries summaries){
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
|
@ -1537,13 +1554,22 @@ class _DestinationHomeState extends State<DestinationHome> {
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_transition = AnimationController(vsync: this, value: 0, duration: Durations.long4);
|
||||||
|
|
||||||
|
_transition.addListener((){
|
||||||
|
setState(() {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FutureBuilder<FetchResults>(
|
return FutureBuilder<FetchResults>(
|
||||||
future: _getData(),
|
future: _data,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
switch (snapshot.connectionState){
|
switch (snapshot.connectionState){
|
||||||
case ConnectionState.none:
|
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));
|
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;
|
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: [
|
children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 450,
|
width: 450,
|
||||||
|
@ -1608,7 +1644,7 @@ class _DestinationHomeState extends State<DestinationHome> {
|
||||||
//if (testNews != null && testNews!.news.isNotEmpty)
|
//if (testNews != null && testNews!.news.isNotEmpty)
|
||||||
Expanded(
|
Expanded(
|
||||||
child: FutureBuilder<News>(
|
child: FutureBuilder<News>(
|
||||||
future: teto.fetchNews(widget.searchFor),
|
future: _newsData,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
switch (snapshot.connectionState){
|
switch (snapshot.connectionState){
|
||||||
case ConnectionState.none:
|
case ConnectionState.none:
|
||||||
|
@ -1640,6 +1676,21 @@ class _DestinationHomeState extends State<DestinationHome> {
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: rightCard != Cards.overview ? widget.constraints.maxHeight - 64 : widget.constraints.maxHeight - 32,
|
height: rightCard != Cards.overview ? widget.constraints.maxHeight - 64 : widget.constraints.maxHeight - 32,
|
||||||
child: SingleChildScrollView(
|
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){
|
child: switch (rightCard){
|
||||||
Cards.overview => getOverviewCard(snapshot.data!.summaries!),
|
Cards.overview => getOverviewCard(snapshot.data!.summaries!),
|
||||||
Cards.tetraLeague => switch (cardMod){
|
Cards.tetraLeague => switch (cardMod){
|
||||||
|
@ -1667,6 +1718,7 @@ class _DestinationHomeState extends State<DestinationHome> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
if (modeButtons[rightCard]!.length > 1) SegmentedButton<CardMod>(
|
if (modeButtons[rightCard]!.length > 1) SegmentedButton<CardMod>(
|
||||||
showSelectedIcon: false,
|
showSelectedIcon: false,
|
||||||
selected: <CardMod>{cardMod},
|
selected: <CardMod>{cardMod},
|
||||||
|
@ -1674,6 +1726,7 @@ class _DestinationHomeState extends State<DestinationHome> {
|
||||||
onSelectionChanged: (p0) {
|
onSelectionChanged: (p0) {
|
||||||
setState(() {
|
setState(() {
|
||||||
cardMod = p0.first;
|
cardMod = p0.first;
|
||||||
|
//_transition.;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -1711,6 +1764,7 @@ class _DestinationHomeState extends State<DestinationHome> {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue