我遇到了这个问题
***> E/flutter (15532): [错误:flutter/lib/ui/ui_dart_state.cc(186)]
<块引用>未处理的异常:FormatException:意外字符(在
字符 1) E/flutter (15532):
E/flutter (15532): ^ E/flutter
(15532): E/flutter (15532): #0 _ChunkedJsonParser.fail
(dart:convert-patch/convert_patch.dart:1404:5) E/flutter (15532): #1
_ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1271:9) E/flutter (15532): #2
_ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:936:22) E/flutter (15532): #3
_parseJson (dart:convert-patch/convert_patch.dart:40:10) E/flutter (15532): #4 JsonDecoder.convert (dart:convert/json.dart:506:36)
E/flutter (15532):#5 JsonCodec.decode
(dart:convert/json.dart:157:41) E/flutter (15532): #6 jsonDecode
(dart:convert/json.dart:96:10) E/flutter (15532): #7
_LoginState.login (package:flutter_login/main.dart:35:18) E/flutter (15532): E/flutter (15532):***
这是我的代码
void main() {
HttpOverrides.global = new MyHttpOverrides();
runApp(MaterialApp(
home: login(),
));
}
class login extends StatefulWidget {
@override
_LoginState createState() => _LoginState();
}
class _LoginState extends State<login>{
var email,password;
final _key = new GlobalKey<FormState>();
check(){
final form = _key.currentState;
if(form.validate()){
form.save();
login();
}
}
login() async{
final response = await http.post(Uri.parse("link"),
body: {
"email" : email,
"password" : password
});
final data = jsonDecode(response.body);
print(data);
}
bool _secureText = false;
showHide(){
setState(() {
_secureText = !_secureText;
});
}
可以帮我吗?请
答案 0 :(得分:0)
在我看来,您的 Uri 解析失败了,因为您已经通过了 "link" 这是一个无效的 uri。
这是来自Uri.parse
docs:
如果 uri 字符串作为 URI 或 URI 引用无效,则抛出 FormatException。