我是flutter的新手,我想從快照中獲取資料并加載到螢屏,但遇到了這個例外,我該如何修復它,對不起,我的英語不好
事務資料庫.dart
class TransactionDB {
String dbName;
TransactionDB({required this.dbName});
//HERE I TRY TO LOAD DATA FROM LOCAL DB AND GET DATA FROM LIST<DYNAMIC> IS THIS USABLE TO GET DATA AND TAKE IT TO SCREEN
Future<List<dynamic>> loaddata() async {
var db = await opendb();
var store = intMapStoreFactory.store('expense');
//find = select find return list snapshot
var snapshot = await store.find(db);
List transactionList = <Transactions>[]; //<<< IS THIS BE LIKE COPY STRUCTOR?
for (var record in snapshot) {
transactionList.add(Transactions(
title: record['title'] as String,
subtitle: record['subtitle'] as String,
date: record['date'] as DateTime)); //<<<<<EXCEPTION BY THIS
}
return transactionList;
}
}
交易提供者.dart
class TransactionProvider with ChangeNotifier {
List<dynamic> transactions = [];
void addTransaction(Transactions statement) async {
var db = TransactionDB(
dbName:
'transactions.db');
//select data to db
transactions = await db.loaddata();
notifyListeners();
}
}
交易.dart
class Transactions {
String title ;
String? subtitle ;
DateTime date ;
Transactions({required this.title,required this.subtitle,required this.date});
}
uj5u.com熱心網友回復:
您的服務正在回傳(可能)一個字串型別(不是日期時間型別),因此 Dart 無法將字串解釋為日期時間。為此,而不是date: record['date'] as DateTime使用date: DateTime.parse(record['date'] as String)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/370363.html
標籤:扑
上一篇:如何使整個頁面在顫動中可滾動
