我这个星期在写代码的时候,出现了一个错误。因为我是新手,无法解决这个问题。
错误。
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']);
},
),
],
),
),
);
}
}
也许删除。
var nome = nome1.value;
var sobrenome = sobrenome1.value;
会有帮助吗?我不确定,但希望它的工作