This repository has been archived by the owner on Aug 10, 2020. It is now read-only.
/
renderGraph.dart
87 lines (71 loc) · 2.37 KB
/
renderGraph.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import '../definitions.dart';
import '../node/login.dart';
import 'package:flutter/material.dart';
abstract class Transition {
Widget create(Animation<double> animation, Widget from, Widget to, bool reverse);
}
class PageSlideTransition implements Transition {
Widget create(Animation<double> animation, Widget from, Widget to, bool reverse) {
return Stack(textDirection: TextDirection.ltr, children: <Widget>[
SlideTransition(
position: Tween<Offset>(
begin: Offset.zero,
end: Offset(reverse ? 1.0 : -1.0, 0.0),
).animate(animation),
child: from,
),
SlideTransition(
position: Tween<Offset>(
begin: Offset(reverse ? -1.0 : 1.0, 0.0),
end: Offset.zero,
).animate(animation),
child: to,
)
]);
}
}
class RenderGraph {
static Widget _current;
static AnimationController _animationController;
static TickerProviderStateMixin _state;
static initialize(TickerProviderStateMixin state) {
_state = state;
}
static Widget build(StateTransition state) {
var buildState = _build(state);
if (_current == null) {
_current = buildState.widget;
return _current;
} else {
if (buildState.transition is PageSlideTransition) {
_animationController = new AnimationController(
vsync: _state, duration: const Duration(milliseconds: 1000));
var transition = (buildState.transition as PageSlideTransition)
.create(_animationController, _current, buildState.widget, state.reverse);
_current = buildState.widget;
_animationController.forward();
state.reverse = false;
return transition;
} else {
return buildState.widget;
}
}
}
static WidgetState _build(StateTransition state) {
// Compiled state management
if (state.branch == Branch.login)
return WidgetState(LoginNode.render(state),
transition: PageSlideTransition());
return WidgetState(_unknownState());
}
static Widget _unknownState() {
return new Center(
child:
Text('Entered an unknown state', textDirection: TextDirection.ltr));
}
}
class WidgetState {
WidgetState(this.widget, {this.transition});
final Widget widget;
final Transition transition;
}