成功注册后,应用程序验证不会呈现到下一个屏幕(通常显示“无数据”)。 我想在成功注册后重定向到包含 Gridview 的下一页。
这样做的最佳方法是什么?谢谢!
代码第一屏:
void _register() async {
setState(() {
_isLoading = true;
});
var data = {
'name': nameController.text,
'surname': surnameController.text,
'gender': genderController.text,
'birthdate': birthdateController.text,
'email': emailController.text,
'password': passwordController.text,
'password_confirmation': password_ConfirmationController.text,
'phone': phoneController.text,
};
var res = await Network().authData(data, '/auth/register');
var body = json.decode(res.body);
if (body['code'] == 0) {
SharedPreferences localStorage = await SharedPreferences.getInstance();
localStorage.setString('access_token', json.encode(body['access_token']));
localStorage.setString('user', json.encode(body['user']));
Navigator.push(
context,
new MaterialPageRoute(builder: (context) => Menu()),
);
} else {
_showMsg(body['message']);
}
setState(() {
_isLoading = false;
});
}
}
第二屏菜单中的代码(希望注册后出现):
body: Center(
child: FutureBuilder<List<dynamic>>(
future: getJokes(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text('none');
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
case ConnectionState.active:
return Text('salut');
case ConnectionState.done:
if (snapshot.hasError) {
return Text(
'${snapshot.error.toString()}',
style: TextStyle(color: Colors.red),
);
} else {
if (!snapshot.hasData) {
return Text('no data');
} else {}
return GridView.builder(
itemCount: snapshot.data.length,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.6,
mainAxisSpacing: 6.0,
crossAxisSpacing: 6.0,
),
itemBuilder: (BuildContext context, int index) {
String pic = snapshot.data[index]['picture1'];
String price = snapshot.data[index]['price'];
String size = snapshot.data[index]['size'];
int id =
int.parse('${snapshot.data[index]['user_id']}');
String ownerpic =
snapshot.data[index]['ownerpicture'];
return Card(
color: Colors.grey[100],
child: Padding(
padding: EdgeInsets.only(
left: 10.0,
right: 10.0,
bottom: 10.0,
top: 10.0),
child: Container(
alignment: Alignment.center,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Row(
children: [
Positioned(
top: 50,
right: 100,
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
UserProfile(
id: id,
)),
);
},
child: CircleAvatar(
radius: 12.0,
backgroundImage: NetworkImage(
"http://192.*.*.*/users_images/$ownerpic",
headers: {
"authorization":
"Bearer $token",
},
),
),
),