Commit 7ef736f8 authored by Sven Eric Panitz's avatar Sven Eric Panitz
Browse files

catch old hive files problem.

parent fa0a9055
import 'package:cardelli/src/db/boxes.dart';
import 'package:hive/hive.dart';
import 'package:cardelli/src/utils/styling_constants.dart';
import '../model/dto/course_dto.dart';
import '../service/subato_service.dart';
......@@ -74,29 +75,32 @@ class _AllCourseScreenState extends State<AllCourseScreen> {
}
Future<List<CourseDto>> getCourseList() async {
final box = Boxes.getCourseDtos();
if (_courseDtos.isNotEmpty) {
return _courseDtos;
}
var res = await SubatoService().getAllCourses();
var courseNames = box.values.map((c)=> c.name);
// print(res);
try{
final box = Boxes.getCourseDtos();
var courseNames = box.values.map((c)=> c.name);
for (var course in res) {
if (!courseNames.contains(course.name)){
box.put(course.uid, course);
for (var course in res) {
if (!courseNames.contains(course.name)){
box.put(course.uid, course);
}else{
}
} //TODO - save all Courses immidiately ????
if(lehrbriefe){
_courseDtos.addAll(box.values.where((c)=>c.lehrbrief));
}else{
_courseDtos.addAll(box.values.where((c)=>!c.lehrbrief));
}
} //TODO - save all Courses immidiately ????
if(lehrbriefe){
_courseDtos.addAll(box.values.where((c)=>c.lehrbrief));
}else{
_courseDtos.addAll(box.values.where((c)=>!c.lehrbrief));
}
}catch (e){
//this is the case, when th Hive file was old version, corrupted or anything strange.
Hive.box<CourseDto>('course_dtos').clear();
};
_courseDtos.sort((a, b) => a.name.compareTo(b.name));
_filteredCourses.addAll(_courseDtos);
......@@ -146,8 +150,8 @@ class _AllCourseScreenState extends State<AllCourseScreen> {
)
)
.toList()); */
return const Text(
"Error retrieving data\n Maybe Subato is down or you have no internet connection");
return Text(
"Error retrieving data: "+((snapshot.error?.toString())??"")+"\n Maybe Subato is down or you have no internet connection");
} else if (snapshot.hasData) {
//onSearchClicked();
return
......
Supports Markdown
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