import 'package:flutter/material.dart';
import'package:flutter_jdshop/services/ScreenAdapter.dart';
import'package:flutter_jdshop/services/Storage.dart';
import'package:flutter_jdshop/services/UserServices.dart';
import'package:flutter_jdshop/widget/JdButton.dart';
import'../../services/EventBus.dart';classUserPage extends StatefulWidget {
UserPage({Key key}) : super(key: key);
_UserPageState createState()=>_UserPageState();
}class _UserPageState extends State{bool isLogin = false;
List userInfo=[];
@overridevoidinitState() {//TODO: implement initState
super.initState();this._getUserinfo();//监听登录页面改变的事件:
eventBus.on().listen((event) {
print(event.str);this._getUserinfo();
});
}
_getUserinfo()async{var isLogin = awaitUserServices.getUserLoginState();var userInfo = awaitUserServices.getUserInfo();
print(userInfo);
print(isLogin);
setState(() {this.userInfo =userInfo;this.isLogin =isLogin;
});
}
@override
Widget build(BuildContext context) {returnScaffold(
appBar: AppBar(
title: Text("用户中心"),
),
body: ListView(
children:[
Container(
height: ScreenAdapter.height(220),
width:double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/user_bg.jpg'),
fit: BoxFit.cover)),
child: Row(
children:[
Container(
margin: EdgeInsets.fromLTRB(10, 0, 10, 0),
child: ClipOval(
child: Image.asset('images/user.png',
fit: BoxFit.cover,
width: ScreenAdapter.width(100),
height: ScreenAdapter.width(100),
),
),
),!this.isLogin?Expanded(
flex:1,
child: InkWell(
onTap: () {
Navigator.pushNamed(context,'/login');
},
child: Text('登录/注册',
style: TextStyle(color: Colors.white)),
),
)
: Expanded(
flex:1,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children:[
Text("用户名:${this.userInfo[0]["username"]}",
style: TextStyle(
color: Colors.white,
fontSize: ScreenAdapter.size(32))),
Text("普通会员",
style: TextStyle(
color: Colors.white,
fontSize: ScreenAdapter.size(32)))
],
),
),
],
),
),
ListTile(
leading: Icon(Icons.home, color: Colors.red), title: Text('首页')),
Divider(),
ListTile(leading: Icon(Icons.home), title: Text('首页')),
ListTile(leading: Icon(Icons.home), title: Text('首页')),
ListTile(leading: Icon(Icons.home), title: Text('首页')),this.isLogin?Container(
padding: EdgeInsets.all(20),
child: JdButton(
color: Colors.red,
text:"退出登录",
cb: () {
UserServices.loginOut();this._getUserinfo();
},
),
)
: Text("")
],
),
);
}
}