-1

I was writing my code this week and I got an error. I can't solve the problem because I am new at this language.

Error:

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)

My code:

    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']);
                    },
                ),
              ],
            ),
          ),
        );
      }
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Theo2017BR
  • 11
  • 2
  • welcome ..remove unwanted text and explain your query .refer this link for asking best question `https://stackoverflow.com/help/how-to-ask` – Ajay Mistry Jun 11 '20 at 15:18

1 Answers1

0

Maybe delete:

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

would help? I am not sure but hope it works!

Net Natnicha
  • 286
  • 2
  • 5