Flutter floor db cannot define return type

82 Views Asked by At

This is my model.

class JoinedResults {
  final int? id;
  final int? question_id;
  final String? question_text;
  final String? question_type;
  final bool? is_mandatory;
  final int? correct_option_id;
  final int? option_id;
  final String? option_list_text;

  JoinedResults({
     this.id,
     this.question_id,
     this.question_text,
     this.question_type,
     this.is_mandatory,
     this.correct_option_id,
     this.option_id,
     this.option_list_text,
  });
}



 // daos.dart
import 'package:floor/floor.dart';
import 'package:rasta_app/bloc/questions_model.dart';

@dao
abstract class QuestionDao {

@Query('SELECT Question.question_id, Question.question_text, Question.question_type, Question.is_mandatory, Question.correct_option_id, OptionLists.option_id,OptionLists.option_list_text FROM Question INNER JOIN OptionLists ON Question.question_id = OptionLists.questionId')
  Future<List<JoinedResults>> getAllQuestionsWithOptions();    
}

This is the error i am facing, Can not define return type

Future<List<JoinedResults>> getAllQuestionsWithOptions();

I am using floor database in flutter i have two Tables One is "Question" and Second is "OptionLists" and Now i want to implement inner Join Query at both tables and then fetch the data and map it into a custom data type list named "JoinedResults" but i am keep getting below error :

This is the error i am facing

Can not define return type package:rasta_app/bloc/question_dao.dart:14:31

 Future<List<JoinedResults>> getAllQuestionsWithOptions();
2

There are 2 best solutions below

0
hace On

I've never used floor, but I think the problem is you're trying to make DAO out of a plain dart class. You should make your JoinedResult class an entity, or a view. Refer to https://pinchbv.github.io/floor/database-views/ for more documentation

0
Vladyslav Ulianytskyi On

You can't return some object from DAO that is not part of DAO. So you should handle it above DAO. As an option you should use streams. more detail here: Floore streams

example1, example2