471 lines
19 KiB
Dart
471 lines
19 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:talk/tools/me/me_model.dart';
|
|
|
|
import '../../beans/me_character_info_bean.dart';
|
|
import '../../beans/user_info_bean.dart';
|
|
import '../../common/EventBusUtil.dart';
|
|
import '../../common/Global.dart';
|
|
import '../../network/NetworkConfig.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;
|
|
StreamSubscription<RefreshUserdata>? _refreshUserdata;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
//支付完成
|
|
_refreshUserdata = EventBusUtil.listen((event) {
|
|
_loadData();
|
|
});
|
|
|
|
subscription = _viewmodel.streamController.stream.listen((newData) {
|
|
String code = newData['code'];
|
|
if (code.isNotEmpty) {
|
|
switch (code) {
|
|
case "getUserInfo":
|
|
userInfoBean = newData['data'];
|
|
break;
|
|
}
|
|
setState(() {});
|
|
}
|
|
});
|
|
_loadData();
|
|
}
|
|
|
|
_loadData() {
|
|
_viewmodel.getUserInfo();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
_refreshUserdata?.cancel();
|
|
subscription.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
goChatPage(String id) {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => ChatPage(
|
|
characterId: id,
|
|
)),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final size = MediaQuery.of(context).size;
|
|
final w21 = size.width / 17.142857142857;
|
|
final t38 = size.width / 9.4736842105263;
|
|
final w58 = size.width / 6.2068965517241;
|
|
final l80 = size.width / 4.5;
|
|
final h50 = size.width / 7.2;
|
|
|
|
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: [
|
|
const Text(
|
|
'',
|
|
style: TextStyle(color: Colors.white, fontSize: 18),
|
|
),
|
|
|
|
///设置按钮
|
|
Positioned(
|
|
right: 15,
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
Navigator.pushNamed(context, '/SettingPage');
|
|
},
|
|
child: Image(
|
|
width: w21,
|
|
height: w21,
|
|
image: AssetImage('assets/images/ic_setting.png'),
|
|
),
|
|
))
|
|
],
|
|
),
|
|
),
|
|
|
|
Container(
|
|
width: double.infinity,
|
|
margin: EdgeInsets.only(left: 18, right: 18, top: t38),
|
|
child: Stack(
|
|
children: [
|
|
ClipOval(
|
|
child: CachedNetworkImage(
|
|
width: w58,
|
|
height: w58,
|
|
imageUrl: userInfoBean.userIconUrl!,
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
Positioned(
|
|
top: 5,
|
|
left: l80,
|
|
child: Text(
|
|
'${userInfoBean.nickName}',
|
|
style: TextStyle(fontSize: 15, color: Color(0xFFE1E1E1)),
|
|
)),
|
|
Positioned(
|
|
bottom: 6,
|
|
left: l80,
|
|
child: Text(
|
|
'id ${userInfoBean.userId}',
|
|
style: TextStyle(fontSize: 13, color: Color(0xFF4D4D4D)),
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
!NetworkConfig.isTeenage
|
|
? 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: 6, right: 2),
|
|
child: Text(
|
|
'聊过',
|
|
style: TextStyle(color: Color(0xFF4D4D4D), fontSize: 12),
|
|
),
|
|
),
|
|
Text(
|
|
'${userInfoBean.hasTalked}',
|
|
style: TextStyle(color: Color(0xFFFF9000), fontSize: 16),
|
|
),
|
|
|
|
Container(
|
|
margin: EdgeInsets.only(left: 25, right: 2),
|
|
child: Text(
|
|
'剩余聊天次数',
|
|
style: TextStyle(color: Color(0xFF4D4D4D), fontSize: 12),
|
|
),
|
|
),
|
|
|
|
Text(
|
|
'${userInfoBean.remainingChatCount}',
|
|
style: const TextStyle(color: Color(0xFFFF9000), fontSize: 17),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: Container(),
|
|
|
|
NetworkConfig.isTeenage
|
|
? Container(
|
|
margin: EdgeInsets.only(top: 10),
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
alignment: Alignment.center,
|
|
child: Image(width: 50, image: const AssetImage('assets/images/ic_teenage.png')),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 43),
|
|
alignment: Alignment.center,
|
|
child: Image(width: 220, image: const AssetImage('assets/images/teenage_explain.png')),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
if (NetworkConfig.isTeenage) {
|
|
Navigator.pushNamed(context, '/CloseTeenageModePage');
|
|
} else {
|
|
Navigator.pushNamed(context, '/TeenagePasswordPage');
|
|
}
|
|
},
|
|
child: Container(
|
|
width: double.infinity,
|
|
height: 45,
|
|
alignment: Alignment.center,
|
|
margin: const EdgeInsets.only(left: 16, right: 16, top: 60),
|
|
decoration: const BoxDecoration(color: Color(0xFFFF9000), borderRadius: BorderRadius.all(Radius.circular(10))),
|
|
child: Text("关闭青少年模式"),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: Container(),
|
|
|
|
///货币 商城
|
|
!NetworkConfig.isTeenage
|
|
? Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 22),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
Navigator.pushNamed(context, '/AccountPage');
|
|
},
|
|
child: Container(
|
|
height: t38,
|
|
decoration: BoxDecoration(color: Color(0xFF2A2A2A), borderRadius: BorderRadius.all(Radius.circular(7))),
|
|
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),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Container(width: 15),
|
|
Expanded(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
Navigator.pushNamed(context, '/ShopPage');
|
|
},
|
|
child: Container(
|
|
height: t38,
|
|
decoration: const BoxDecoration(color: Color(0xFF2A2A2A), borderRadius: BorderRadius.all(Radius.circular(7))),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
margin: const EdgeInsets.only(left: 15),
|
|
child: const Image(
|
|
width: 23,
|
|
height: 20,
|
|
image: AssetImage('assets/images/ic_mall.png'),
|
|
),
|
|
),
|
|
Container(
|
|
margin: const EdgeInsets.only(left: 35),
|
|
child: const Text(
|
|
'商城',
|
|
style: TextStyle(color: Color(0xFFE1E1E1), fontSize: 13),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: Container(),
|
|
|
|
///看广告
|
|
GestureDetector(
|
|
onTap: () {
|
|
Map<String, dynamic> map = {
|
|
"playAd": "playAd",
|
|
};
|
|
invokeNativeMethod("playAd", map);
|
|
},
|
|
child: Container(
|
|
width: size.width,
|
|
height: 62,
|
|
margin: EdgeInsets.only(left: 15, right: 15, top: 20),
|
|
decoration: const BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(10)),
|
|
gradient: LinearGradient(
|
|
begin: Alignment.centerLeft,
|
|
end: Alignment.centerRight,
|
|
colors: [
|
|
Color(0xFFB0B6D3),
|
|
Color(0xFF96A5F5),
|
|
],
|
|
),
|
|
),
|
|
child: const Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Positioned(
|
|
top: 15,
|
|
left: 12,
|
|
child: Text(
|
|
"看广告获得聊天次数",
|
|
style: TextStyle(fontSize: 12, color: Color(0xFF3248B6)),
|
|
)),
|
|
Positioned(
|
|
top: 34,
|
|
left: 12,
|
|
child: Text(
|
|
"看一次广告可获得10次聊天",
|
|
style: TextStyle(fontSize: 15, color: Color(0xFF3248B5)),
|
|
)),
|
|
Positioned(right: 15, child: Image(width: 36, height: 36, image: AssetImage('assets/images/ic_ad.png')))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
// Container(
|
|
// height: h50,
|
|
// margin: EdgeInsets.symmetric(horizontal: 16),
|
|
// child: GestureDetector(
|
|
// onTap: () {
|
|
// // Navigator.pushNamed(context, '/LoginPage');
|
|
// },
|
|
// child: CachedNetworkImage(
|
|
// width: w58,
|
|
// height: w58,
|
|
// imageUrl: userInfoBean.inviteNewUser!.imgUrl!,
|
|
// errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
|
|
// 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();
|
|
}
|
|
|
|
// 获取原生的值
|
|
invokeNativeMethod(String method, Map<String, dynamic> map) async {
|
|
dynamic args;
|
|
try {
|
|
args = await Global.method.invokeMethod(method, map);
|
|
} on PlatformException catch (e) {}
|
|
}
|
|
}
|