flutter 登录和退出登录_36 Flutter仿京东商城项目 用户登录 退出登录 事件广播更新状态...

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("")

],

),

);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值