我尝试为用户创建登录页面,但出现错误类型'_InternalLinkedHashMap
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:onefrist/main.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'MyPreferences.dart';
import 'main.dart';
import 'Registration.dart';
void main() => runApp(loginpage());
String getid;
class loginpage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.amber,
title: Text('User Login Form')),
body: Center(
child: LoginUser()
)
)
);
}
}
class LoginUser extends StatefulWidget {
LoginUserState createState() => LoginUserState();
}
class LoginUserState extends State <LoginUser>{
MyPreferences _myPreferences = MyPreferences();
var getid;
@override
void initState() {
// TODO: implement initState
super.initState();
_myPreferences.init().then((value) {
setState(() {
_myPreferences = value;
});
});
}
bool visible = false ;
Future userLogin() async{
setState(() {
visible = true ;
});
final emailController = TextEditingController(text: _myPreferences.user);
final passwordController = TextEditingController(text: _myPreferences.password);
String email = emailController.text;
String password = passwordController.text;
if(email == '' || password == '')
{
}else{
var url = 'http://xxxxxxxxx/login_user.php';
var data = {'email': email, 'password' : password};
var response = await http.post(url, body: json.encode(data));
var message = jsonDecode(response.body);
print("tapped ${message['id']}");
getid=message['id'];
_myPreferences.id = getid;
_myPreferences.commit();
if(message['result'] == 'Login Matched')
{
setState(() {
visible = false;
});
Navigator.push(context, MaterialPageRoute(builder: (context) => mainpage(email : emailController.text)));
}else{
setState(() {
visible = false;
});
// Showing Alert Dialog with Response JSON Message.
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: new Text(message),
actions: <Widget>[
FlatButton(
child: new Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);}
}
}
}
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following _TypeError was thrown building Builder(dirty):
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'
The relevant error-causing widget was:
MaterialApp file:///C:/Users/MARWAN/IdeaProjects/onefrist/lib/loginpage.dart:18:12
When the exception was thrown, this was the stack:
#0 LoginUserState.userLogin.<anonymous closure> (package:onefrist/loginpage.dart:112:31)
#1 Builder.build (package:flutter/src/widgets/basic.dart:7118:48)
#2 StatelessElement.build (package:flutter/src/widgets/framework.dart:4620:28)
#3 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4546:15)
#4 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
如果有人知道解决方案对我有帮助
答案 0 :(得分:0)
Map<String,dynamic> message = jsonDecode(response.body);
请尝试