【发布时间】:2021-07-21 04:27:33
【问题描述】:
Error I got: The following ArgumentError was thrown building FutureBuilder<List<Transaction>>(dirty, state: _FutureBuilderState<List<Transaction>>#b741e):
Invalid argument(s) (input): Must not be null
When the exception was thrown, this was the stack:
#0 _RegExp.firstMatch (dart:core-patch/regexp_patch.dart:221:24)
#1 DateTime.parse (dart:core/date_time.dart:266:23)
#2 new transactionByDate (package:bug3t/widgets/transactionByDate.dart:16:20)
#3 _BudgetDateRangePickerState.build.<anonymous closure> (package:bug3t/widgets/date_picker.dart:80:19)
#4 _FutureBuilderState.build (package:flutter/src/widgets/async.dart:773:55)
#1 date_time.dart (lib)
static DateTime parse(String formattedString) {
var re = _parseFormat;
**Match? match = re.firstMatch(formattedString);**
if (match != null) {
int parseIntOrZero(String? matched) {
if (matched == null) return 0;
return int.parse(matched);
}
#2 transactionByDate.dart( 我用这个来过滤交易 JSON 文件)
class transactionByDate extends StatelessWidget {
final List<Transaction> transactions;
final DateTime from;
final DateTime to;
transactionByDate( this.transactions, this.from, this.to) {
for (int i = 0; i < transactions.length; i++) {
**if (DateTime.parse(transactions[i].date).isAfter(this.to) || DateTime.parse(transactions[i].date).isBefore(this.from))** {
this.transactions.remove(transactions[i]);
}
}
}
#3 date_picker.dart(我使用这个类来传递来自日期选择器的数据和从互联网上获取的 JSON 列表)
child: new FutureBuilder<List<Transaction>>(
future: fetchBudgetTrans(new http.Client()),builder: (context, snapshot) {if (snapshot.hasError) print(snapshot.error);
if (snapshot.hasData) {
**transactionByDate tl = new transactionByDate(snapshot.data,_fromDate,_toDate);**
return Flexible(child: tl);} else return new Center(child: new CircularProgressIndicator()); },)
【问题讨论】: