Sqlite 如何在Flatter moor中创建双值列
我使用flatter_moor创建SQLite数据库。我有一个问题,我需要一列货币金额的双精度小数点后两位 我发现有一个RealColumn,但没有找到如何正确地实现它Sqlite 如何在Flatter moor中创建双值列,sqlite,flutter,flutter-moor,Sqlite,Flutter,Flutter Moor,我使用flatter_moor创建SQLite数据库。我有一个问题,我需要一列货币金额的双精度小数点后两位 我发现有一个RealColumn,但没有找到如何正确地实现它 /// A column that stores floating point numeric values./// abstract class RealColumn extends Column<double, RealType> {} real列中的double()不起作用。我认为它和int或te
/// A column that stores floating point numeric values.///
abstract class RealColumn extends Column<double, RealType> {}
real列中的double()不起作用。我认为它和int或text是一样的。
我在文档和web中找不到解决方案。我的问题是,让amount列工作的正确方法是什么 非常感谢您的帮助。
----编辑:----
完整文件:
import 'dart:core';
import 'package:moor/moor.dart';
import 'package:moor_flutter/moor_flutter.dart';
part 'moor_database.g.dart';
class Transactions extends Table {
IntColumn get id => integer().autoIncrement()();
TextColumn get title => text().withLength(min: 1, max: 35)();
TextColumn get description => text().withLength(min: 0, max: 50)();
TextColumn get categorie => text().withLength(min: 1, max: 35)();
RealColumn get amount => double()(); //!!!<---This is line with the error///
DateTimeColumn get date => dateTime()();
}
@UseMoor(tables: [Transactions])
class AppDatabase extends _$AppDatabase {
AppDatabase()
: super((FlutterQueryExecutor.inDatabaseFolder(
path: 'db.sqlite',
logStatements: true,
)));
@override
int get schemaVersion => 1;
Future<List<Transaction>> getAllTasks() => select(transactions).get();
Stream<List<Transaction>> watchAllTasks() => select(transactions).watch();
Future insertTask(Transaction transaction) => into(transactions).insert(transaction);
Future updateTask(Transaction transaction) => update(transactions).replace(transaction);
Future deleteTask(Transaction transaction) => delete(transactions).delete(transaction);
}
我不明白这个错误以及为什么double()不起作用
我希望这有帮助:)您应该使用real()而不是double(),如下所示:
RealColumn get amount => real()();
它怎么不起作用?你应该添加更多的信息,比如sqlite抛出的错误,或者至少更详细地描述你的问题。非常感谢你的帮助!!!它很好用。在我看了你的答案后,我发现它应该是真实的:)。IntColumn=int…RealColumn=real。很好,如果这个答案解决了您的问题,您应该将它标记为已接受,以便其他人可以看到它。
IntColumn get amount => integer()();
RealColumn get amount => real()();