-
Notifications
You must be signed in to change notification settings - Fork 3
/
gramola_timeline.dart
186 lines (160 loc) · 5.72 KB
/
gramola_timeline.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
library gramola_timeline;
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:flutter_flux/flutter_flux.dart';
import 'package:fh_sdk/fh_sdk.dart';
import 'package:gramola_timeline/config/stores.dart';
import 'package:gramola_timeline/timeline_entry_row.dart';
/// A Calculator.
class Calculator {
/// Returns [value] plus 1.
int addOne(int value) => value + 1;
}
class EventTimelineComponent extends StatefulWidget {
EventTimelineComponent(TimelineConfiguration configuration)
: this._configuration = configuration;
final TimelineConfiguration _configuration;
@override
_EventsComponentState createState() => new _EventsComponentState(this._configuration);
}
class _EventsComponentState extends State<EventTimelineComponent>
with StoreWatcherMixin<EventTimelineComponent>{
final scaffoldKey = new GlobalKey<ScaffoldState>();
final GlobalKey<AnimatedListState> _listKey = new GlobalKey<AnimatedListState>();
_EventsComponentState(TimelineConfiguration configuration)
: this._configuration = configuration;
final TimelineConfiguration _configuration;
// Never write to these stores directly. Use Actions.
TimelineStore timelineStore;
@override
void initState() {
super.initState();
// Demonstrates using a custom change handler.
timelineStore = listenToStore(timelineStoreToken, handleTimelineStoreChanged);
_fetchTimeline();
}
void handleTimelineStoreChanged(Store value) {
setState(() {});
}
void _fetchTimeline() async {
assert(timelineStore != null);
try {
//setConfiguration(this._configuration);
fetchTimelineEntriesRequestAction('');
Map<String, dynamic> options = {
"path": "/timeline/" + this._configuration.eventId + "/" + this._configuration.userId,
"method": "GET",
"contentType": "application/json",
"timeout": 25000 // timeout value specified in milliseconds. Default: 60000 (60s)
};
dynamic result = await FhSdk.cloud(options);
fetchTimelineEntriesSuccessAction(result);
} on PlatformException catch (e) {
fetchTimelineEntriesFailureAction(e.message);
print('PlatformException e: ' + e.toString());
_showSnackbar('Error retrieving timeline!');
}
}
void _showSnackbar (String message) {
// This is just a demo, so no actual login here.
final snackbar = new SnackBar(
content: new Text(message),
);
scaffoldKey.currentState.showSnackBar(snackbar);
}
void _showAddEntryDialog() {
final TextEditingController _titleFieldController = new TextEditingController();
final TextEditingController _descriptionFieldController = new TextEditingController();
Container formSection = new Container(
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
new ListTile(
leading: const Icon(Icons.title),
title: new TextField(
controller: _titleFieldController,
autocorrect: false,
decoration: new InputDecoration(
hintText: "Title",
),
),
),
new ListTile(
leading: const Icon(Icons.description),
title: new TextField(
controller: _descriptionFieldController,
autocorrect: false,
decoration: new InputDecoration(
hintText: "Description",
),
),
)
],
)
);
showModalBottomSheet<void>(context: context, builder: (BuildContext context) {
return new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
formSection,
new Container(
padding: const EdgeInsets.fromLTRB(0.0, 8.0, 0.0, 0.0),
child: new RaisedButton(
child: new Text('Add'),
color: Theme.of(context).primaryColor,
textColor: Colors.white,
onPressed: null
)
)
]
);
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
key: scaffoldKey,
appBar: new AppBar(
title: new Text('Timeline'),
leading: new IconButton(
tooltip: 'Go back',
icon: const Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(scaffoldKey.currentContext);
},
),
centerTitle: true,
),
body: new Column(
children: <Widget>[
new Flexible(
child: new Container(
child: new ListView.builder(
itemCount: timelineStore.timelineEntries.length > 0 ? timelineStore.timelineEntries.length + 1 : 0,
itemBuilder: (_, index) {
if (index < timelineStore.timelineEntries.length) {
return new TimelineEntryRow(
lineColor: Theme.of(context).accentColor,
backgroundColor: Theme.of(context).canvasColor,
imagesBaseUrl: timelineStore.imagesBaseUrl,
entry: timelineStore.timelineEntries[index]);
}
return new TimelineEntryEnding(
color: Theme.of(context).accentColor,
backgroundColor: Theme.of(context).canvasColor
);
}
),
),
)
]
),
floatingActionButton: new FloatingActionButton(
tooltip: 'Add', // used by assistive technologies
child: new Icon(Icons.add),
onPressed: _showAddEntryDialog
)
);
}
}