335 lines
12 KiB
Dart
335 lines
12 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:talk/tools/me/me_model.dart';
|
|
|
|
import '../../beans/me_character_info_bean.dart';
|
|
import '../../beans/user_info_bean.dart';
|
|
import '../chat/chat_page.dart';
|
|
|
|
class MePage extends StatefulWidget {
|
|
const MePage({super.key});
|
|
|
|
@override
|
|
State<MePage> createState() => _MePageState();
|
|
}
|
|
|
|
class _MePageState extends State<MePage> {
|
|
late StreamSubscription subscription;
|
|
final MeModel _viewmodel = MeModel();
|
|
|
|
late UserInfoBean userInfoBean;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
|
|
subscription = _viewmodel.streamController.stream.listen((newData) {
|
|
String code = newData['code'];
|
|
if (code.isNotEmpty) {
|
|
switch (code) {
|
|
case "getUserInfo":
|
|
userInfoBean = newData['data'];
|
|
break;
|
|
}
|
|
setState(() {});
|
|
}
|
|
});
|
|
_viewmodel.getUserInfo();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
subscription.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
goChatPage(String id) {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => ChatPage(
|
|
characterId: id,
|
|
)),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Color(0xFF121213),
|
|
body: SingleChildScrollView(
|
|
child: Stack(
|
|
children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top + 9),
|
|
child: Column(
|
|
children: [
|
|
///title
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Text(
|
|
'',
|
|
style: TextStyle(color: Colors.white, fontSize: 18),
|
|
),
|
|
///设置按钮
|
|
Positioned(
|
|
right: 15,
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
Navigator.pushNamed(context, '/SettingPage');
|
|
},
|
|
child: Image(
|
|
width: 21,
|
|
height: 21,
|
|
image: AssetImage('assets/images/ic_setting.png'),
|
|
),
|
|
))
|
|
],
|
|
),
|
|
),
|
|
|
|
Container(
|
|
width: double.infinity,
|
|
margin: EdgeInsets.only(left: 18, right: 18, top: 38),
|
|
child: Stack(
|
|
children: [
|
|
ClipOval(
|
|
child: CachedNetworkImage(
|
|
width: 58,
|
|
height: 58,
|
|
imageUrl: userInfoBean.userIconUrl!,
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
Positioned(
|
|
top: 5,
|
|
left: 80,
|
|
child: Text(
|
|
'${userInfoBean.nickName}',
|
|
style: TextStyle(fontSize: 15, color: Color(0xFFE1E1E1)),
|
|
)),
|
|
Positioned(
|
|
bottom: 6,
|
|
left: 80,
|
|
child: Text(
|
|
'id ${userInfoBean.userId}',
|
|
style: TextStyle(fontSize: 13, color: Color(0xFF4D4D4D)),
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 16, top: 17),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'9',
|
|
style: TextStyle(color: Colors.white, fontSize: 16),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 6),
|
|
child: Text(
|
|
'相册',
|
|
style: TextStyle(color: Color(0xFF4D4D4D), fontSize: 12),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 22),
|
|
child: Text(
|
|
'9',
|
|
style: TextStyle(color: Colors.white, fontSize: 16),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 6),
|
|
child: Text(
|
|
'聊过',
|
|
style: TextStyle(color: Color(0xFF4D4D4D), fontSize: 12),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
///货币 商城
|
|
Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 22),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.pushNamed(context, '/AccountPage');
|
|
},
|
|
child: Container(
|
|
width: 151,
|
|
height: 38,
|
|
decoration: BoxDecoration(color: Color(0xFF2A2A2A), borderRadius: BorderRadius.all(Radius.circular(13))),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
margin: EdgeInsets.only(left: 15),
|
|
child: Image(
|
|
width: 23,
|
|
height: 20,
|
|
image: AssetImage('assets/images/ic_currency.png'),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 17),
|
|
child: Text(
|
|
'货币:${userInfoBean.currency}',
|
|
style: TextStyle(color: Color(0xFFE1E1E1), fontSize: 13),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.pushNamed(context, '/ShopPage');
|
|
},
|
|
child: Container(
|
|
width: 151,
|
|
height: 38,
|
|
margin: EdgeInsets.only(left: 26),
|
|
decoration: BoxDecoration(color: Color(0xFF2A2A2A), borderRadius: BorderRadius.all(Radius.circular(13))),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
margin: EdgeInsets.only(left: 15),
|
|
child: Image(
|
|
width: 23,
|
|
height: 20,
|
|
image: AssetImage('assets/images/ic_mall.png'),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 24),
|
|
child: Text(
|
|
'货币商城',
|
|
style: TextStyle(color: Color(0xFFE1E1E1), fontSize: 13),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
Container(
|
|
height: 50,
|
|
margin: EdgeInsets.symmetric(horizontal: 16),
|
|
child: Image(
|
|
image: AssetImage('assets/images/ic_web.png'),
|
|
),
|
|
),
|
|
|
|
Container(
|
|
margin: EdgeInsets.only(left: 16, top: 33),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'创作中心',
|
|
style: TextStyle(color: Color(0xFFE1E1E1)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 9),
|
|
child: Text(
|
|
'0',
|
|
style: TextStyle(color: Color(0xFF4D4D4D)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 17),
|
|
child: GridView.count(
|
|
shrinkWrap: true,
|
|
//水平子Widget之间间距
|
|
crossAxisSpacing: 12.0,
|
|
//垂直子Widget之间间距
|
|
mainAxisSpacing: 9.0,
|
|
//GridView内边距
|
|
padding: EdgeInsets.zero,
|
|
//一行的Widget数量
|
|
crossAxisCount: 3,
|
|
//子Widget宽高比例
|
|
childAspectRatio: 0.7,
|
|
//子Widget列表
|
|
children: _item(userInfoBean.characterInfo!),
|
|
physics: NeverScrollableScrollPhysics(),
|
|
//类似 cellForRow 函数
|
|
scrollDirection: Axis.vertical),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
_item(List<MeCharacterInfoBean> list) {
|
|
return list.map((res) {
|
|
int index = list.indexOf(res);
|
|
return GestureDetector(
|
|
onTap: () {
|
|
goChatPage(res.characterId.toString());
|
|
},
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
// margin: EdgeInsets.only(right: 9, left: 16),
|
|
child: Stack(
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.all(Radius.circular(15)),
|
|
child: CachedNetworkImage(
|
|
width: 113,
|
|
height: 159,
|
|
fit: BoxFit.cover,
|
|
imageUrl: res.bgImage!,
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
Positioned(
|
|
left: 7,
|
|
bottom: 5,
|
|
child: Text(
|
|
'${res.characterName}',
|
|
style: TextStyle(color: Colors.white, fontSize: 12),
|
|
)),
|
|
// Positioned(
|
|
// left: 7,
|
|
// bottom: 9,
|
|
// child: Container(
|
|
// width: 105,
|
|
// child: Text(
|
|
// '${res.biography}',
|
|
// maxLines: 1,
|
|
// overflow: TextOverflow.ellipsis,
|
|
// style: TextStyle(color: Color(0xFFC2C2C2), fontSize: 9),
|
|
// ),
|
|
// )),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}).toList();
|
|
}
|
|
|
|
}
|