【问题标题】:Invalid argument(s) (input): Must not be null无效参数(输入):不能为空
【发布时间】: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()); },)

【问题讨论】:

    标签: flutter dart


    【解决方案1】:
    if(formattedString == null) 
        Do sth
    

    【讨论】:

    • 但它来自一个库,所以我不想更改该文件中的任何内容。
    • 您可以在 **if 之前进行检查,以确保 transactions[i].date 不为空:
    猜你喜欢
    • 2020-09-07
    • 2020-11-09
    • 2021-10-23
    • 2013-03-10
    • 1970-01-01
    • 2015-12-07
    • 2021-10-01
    • 2012-09-19
    • 1970-01-01
    相关资源
    最近更新 更多