Commit 40b6c78e authored by wonko's avatar wonko

swipe down cache reload

parent 5604bdce
......@@ -23,7 +23,6 @@ class Assets {
class LectureData extends Assets {
static final LectureData _instance = LectureData._internal();
factory LectureData() => _instance;
......@@ -41,22 +40,22 @@ class LectureData extends Assets {
}
LectureData._internal() {
_dataFuture = _getData();
_dataFuture = getData();
_dataFuture.then(_storeSchedule);
}
Future<Lectures> _getData() async {
final DefaultCacheManager dcm = DefaultCacheManager();
final String lurl = 'https://nos.prause.de/lttectures.json';
FileInfo finfo = await dcm.getFileFromCache(lurl);
if (finfo == null){
//preload from assets
var bytes = await rootBundle.load('assets/data/lectures.json');
dcm.putFile(lurl, bytes.buffer.asUint8List());
finfo = await dcm.getFileFromCache(lurl);
}
Future<Lectures> reload() async{
print('reloading');
DefaultCacheManager().emptyCache();
return getData();
}
Future<Lectures> getData() async {
final String lurl = 'https://nos.prause.de/lectures.json';
File file = finfo.file;
print('getting $lurl');
File file = await DefaultCacheManager().getSingleFile(lurl);
print('got $file');
String dataAsString = await file.readAsString();
Map<String, dynamic> json = await jsonDecode(dataAsString);
return Future(() {
......
......@@ -33,7 +33,7 @@ class _ScheduleWidgetState extends State<ScheduleWidget>
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: lectureData.dataFuture,
future: lectureData.getData(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
return snapshot.hasData
? Stack(
......@@ -54,6 +54,7 @@ class _ScheduleWidgetState extends State<ScheduleWidget>
});
}
List<Widget> roomViews() {
List<Widget> rv = [];
for (Room room in lectureData.data.rooms) {
......@@ -97,16 +98,19 @@ class RoomSchedule extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView.builder(
controller: this._scrollController,
itemExtent: 250,
itemCount: room.timeSlots.length,
itemBuilder: (context, index) => Column(children: <Widget>[
Divider(),
Expanded(child: getLectureCard(index, context))
]));
return RefreshIndicator(
onRefresh: LectureData().reload,
child: ListView.builder(
controller: this._scrollController,
itemExtent: 250,
itemCount: room.timeSlots.length,
itemBuilder: (context, index) => Column(children: <Widget>[
Divider(),
Expanded(child: getLectureCard(index, context))
])));
}
Widget getLectureCard(int index, BuildContext context) {
if (room.timeSlots[index].lecture != null) {
Lecture l = room.timeSlots[index].lecture;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment