Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Exception: type 'Null' is not a subtype of type 'double' in type cast #800

Closed
ferut opened this issue Jan 9, 2024 · 1 comment

Comments

@ferut
Copy link

ferut commented Jan 9, 2024

Hi.

I have a Event Entity:

import 'package:floor/floor.dart';

@Entity(tableName: 'EventN') // Use @Entity instead of @entity
class EventN {
  @PrimaryKey(autoGenerate: true)
  final int? id;
  final DateTime date;
  final String description;
  final String category;
  final String subCategory;
  final String mdp;
  final double? amount;
  final String type;
  final String mdpType;
  final String? mdpName;
  EventN({this.id, required this.date, required this.description, required this.category, required this.amount, required this.type, required this.subCategory,required this.mdp, required this.mdpType, this.mdpName });

}

And a EventDao:

import 'package:floor/floor.dart';
import '../entity/event.dart';
@dao
abstract class EventDao {
  @Query('SELECT * FROM EventN')
  Stream<List<EventN>> findAllEvent();

  @Query('SELECT (SUM(CASE WHEN type = \'entrata\' THEN amount ELSE 0 END) - '
      'SUM(CASE WHEN type = \'uscita\' THEN amount ELSE 0 END)) AS net_result '
      'FROM EventN')
  Stream<double?> calculateNetResult();

  @insert
  Future<void> insertEventN(EventN event);
}

The problem is that when my table is empty, my query of calculate net_result gives error as Unhandled Exception: type 'Null' is not a subtype of type 'double' in type cast
I shouldn't use databaseview in this case because it's a single result query right?

@ferut
Copy link
Author

ferut commented Jan 10, 2024

Solved It works. Query was wrong

@ferut ferut closed this as completed Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant