-1

这周我正在编写我的代码,但我遇到了一个错误。我无法解决问题,因为我是这门语言的新手。

错误:

The following NoSuchMethodError was thrown while handling a gesture: The getter 'length' was called 
on null. Receiver: null Tried calling: length
0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
1 _parseJson (dart:convert-patch/convert_patch.dart:30:28)
2 JsonDecoder.convert (dart:convert/json.dart:505:36)
3 JsonCodec.decode (dart:convert/json.dart:153:41)
4 __HomeState.build. (package:fiveo/main.dart:83:30)

我的代码:

    import 'dart:convert';
    import 'package:flutter/cupertino.dart';
    import 'package:flutter/material.dart';
    import 'package:async/async.dart';
    import 'package:http/http.dart' as http;
    import 'package:convert/convert.dart';

    var nome1 = TextEditingController();
    var sobrenome1 = TextEditingController();
    var nome = nome1.value;
    var sobrenome = sobrenome1.value;
    String responsebody;


    dynamic url = "https://completecriminalchecks.com/api/json/?firstname=$nome&lastname=$sobrenome&apikey=v11x15lmnyk7b40pes6ug3";

    Future<void> main() async {
      http.Response response = await http.get(url);
      responsebody = response.body;

      String dadosPessoa() {
        print(json.decode(responsebody)['object']['response']);
      }

      runApp(MaterialApp(
        home: _Home(),
      ));
    }

    class _Home extends StatefulWidget {
      @override

      __HomeState createState() => __HomeState();
    }

    class __HomeState extends State<_Home> {
      String get resultado => null;

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(
                "FIVE-0"),
          ),

          body:
          Form(
            child:
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                TextFormField(
                  controller: nome1,
                  decoration: const InputDecoration(
                    hintText: "Nome do suspeito:",

                  ),
                  validator: (value) {
                    if (value.isEmpty) {
                      return 'Digite o nome sugeito';
                    }
                    return null;
                  },
                ),


                TextFormField(
                  controller: sobrenome1,
                  decoration: const InputDecoration(
                    hintText: "Nome do suspeito:",

                  ),
                  validator: (value) {
                    if (value.isEmpty) {
                      return 'Digite o nome sugeito';
                    }
                    return null;
                  },
                ),
                RaisedButton(
                  onPressed: () {
                    return (json.decode(responsebody)['object']['response']);
                    },
                ),
              ],
            ),
          ),
        );
      }
    }
4

1 回答 1

0

也许删除:

var nome = nome1.value;
var sobrenome = sobrenome1.value;

有助于?我不确定,但希望它有效!

于 2020-06-11T22:41:51.843 回答