我需要制作一个在 api 中搜索名称的应用程序。问题是表单小部件没有发送我在输入中写的名称。
重要的部分是:dadosPessoa()
和Form()
两者TextFormField()
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.text;
var sobrenome = sobrenome1.text;
String responsebody;
dynamic url = "https://completecriminalchecks.com/api/json/?firstname=$nome&lastname=$sobrenome&apikey=fooberry";
Future<void> main() async {
http.Response response = await http.get(url);
responsebody = response.body;
Future<String> dadosPessoa() async {
print(json.decode(responsebody)['person']);
}
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: () {
print(json.decode(responsebody)['person']);
},
),
],
),
),
);
}
}