123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- import 'package:flutter/material.dart';
- import 'package:flutter/rendering.dart';
- import 'package:flutter/services.dart';
- import 'package:provider/provider.dart';
- import 'package:sport/application.dart';
- import 'package:sport/bean/post_user.dart';
- import 'package:sport/bean/user_friend.dart';
- import 'package:sport/bean/user_info.dart';
- import 'package:sport/pages/social/block_user_list_page.dart';
- import 'package:sport/pages/social/user_post_page.dart';
- import 'package:sport/provider/lib/view_state_lifecycle.dart';
- import 'package:sport/provider/user_detail_model.dart';
- import 'package:sport/provider/user_model.dart';
- import 'package:sport/router/navigator_util.dart';
- import 'package:sport/services/api/inject_api.dart';
- import 'package:sport/services/userid.dart';
- import 'package:sport/utils/toast.dart';
- import 'package:sport/widgets/button_primary.dart';
- import 'package:sport/widgets/dialog/request_dialog.dart';
- import 'package:sport/widgets/image.dart';
- import 'package:sport/widgets/misc.dart';
- import 'package:sport/widgets/popmenu_bg.dart';
- import 'package:sport/widgets/space.dart';
- import 'package:sport/widgets/user_widget.dart';
- class UserDetailPage extends StatefulWidget {
- final PostUser user;
- final List<UserFriend>? userFriends;
- UserDetailPage(this.user, {this.userFriends});
- @override
- State<StatefulWidget> createState() => _PageState();
- }
- class _PageState extends ViewStateLifecycle<UserDetailPage, UserDetailModel> with InjectApi, UserId {
- String _genderLabel = "他";
- bool _ready = false;
- late ValueNotifier<UserInfo?> _valueNotifierUserInfo;
- @override
- void initState() {
- super.initState();
- _valueNotifierUserInfo = ValueNotifier(UserInfo.fromJson(widget.user.toJson()));
- _genderLabel = selfId == widget.user.id ? "我" : "她";
- api.getUserInfo(widget.user.id!).then((value) {
- _valueNotifierUserInfo.value = value.data;
- _ready = true;
- _genderLabel = selfId == widget.user.id
- ? "我"
- : value.data?.gender == 1
- ? "他"
- : "她";
- });
- }
- bool isSelf() {
- return selfId == widget.user.id;
- }
- @override
- void dispose() {
- super.dispose();
- _valueNotifierUserInfo.dispose();
- }
- @override
- Widget build(BuildContext context) {
- var menu = [
- if (isSelf()) menuItemCenter('list', '屏蔽列表'),
- if (openSocial() && isSelf()) menuItemCenter('post', '社区帖子'),
- if (openSocial())
- if (!isSelf()) menuItemCenter('block', _valueNotifierUserInfo.value?.blockedFromMe == true ? '取消屏蔽' : '屏蔽此人')
- ];
- return Scaffold(
- backgroundColor: Colors.black.withOpacity(.9),
- appBar: AppBar(
- automaticallyImplyLeading: false,
- backgroundColor: Colors.transparent,
- systemOverlayStyle: SystemUiOverlayStyle.light,
- leading: IconButton(
- icon: Padding(
- padding: const EdgeInsets.all(4.0),
- child: Image.asset(
- "lib/assets/img/btn_close_white.png",
- width: 24,
- ),
- ),
- onPressed: () => Navigator.pop(context, false),
- ),
- actions: [
- if (menu.isNotEmpty)
- PopupMenuTheme(
- data: PopupMenuThemeData(shape: PopmenuShape(borderRadius: BorderRadius.all(Radius.circular(10.0)))),
- child: PopupMenuButton(
- icon: iconMore(),
- onSelected: (val) async {
- switch (val) {
- case 'block':
- if (_valueNotifierUserInfo.value?.blockedFromMe == true) {
- await request(context, () async {
- var resp = await model.api.postForumUnBlockUser("${_valueNotifierUserInfo.value?.id}");
- if (resp.code == 0) {
- ToastUtil.show("取消屏蔽成功");
- _valueNotifierUserInfo.value?.blockedFromMe = false;
- }
- });
- } else {
- await request(context, () async {
- var resp = await model.api.postForumBlockUser("${_valueNotifierUserInfo.value?.id}");
- if (resp.code == 0) {
- ToastUtil.show("屏蔽成功");
- _valueNotifierUserInfo.value?.blockedFromMe = true;
- }
- });
- }
- setState(() {});
- break;
- case 'list':
- NavigatorUtil.goPage(context, (context) => BlockUserListPage());
- break;
- case 'post':
- NavigatorUtil.goPage(context, (context) => UserPostPage(widget.user));
- break;
- }
- },
- offset: Offset(0, kToolbarHeight / 2 + 15),
- itemBuilder: (_) => menu,
- ))
- ],
- ),
- body: Container(
- width: double.infinity,
- height: double.infinity,
- child: Center(
- child: SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Container(
- width: double.infinity,
- child: ValueListenableBuilder(
- valueListenable: _valueNotifierUserInfo,
- builder: (BuildContext context, UserInfo? user, Widget? child) {
- if (user == null) {
- return Container();
- }
- return Column(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- CircleAvatar(backgroundColor: Colors.black26,
- backgroundImage: userAvatarProvider(user.avatar),
- radius: 50,
- ),
- Space(
- height: 13,
- ),
- Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- const SizedBox(
- width: 70,
- ),
- Text(user.name ?? "", style: TextStyle(color: Colors.white, fontSize: 18)),
- ConstrainedBox(constraints: BoxConstraints(minWidth: 70.0), child: UserLevelWidget(level: user.levelInfo)),
- ],
- ),
- Space(
- height: 10,
- ),
- ConstrainedBox(
- child: _ready != true
- ? Container()
- : Row(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Image.asset("lib/assets/img/mine_icon_${user.gender == 1 ? "manl" : "girl"}_white.png"),
- Space(
- width: 4,
- ),
- Text(
- user.gender == 1 ? "男" : "女",
- style: TextStyle(color: Colors.white, fontSize: 12),
- ),
- Space(
- width: 10,
- ),
- if ((user.age ?? 0) > 0)
- Text(
- user.age != null ? "${user.age}岁" : "",
- style: TextStyle(color: Colors.white, fontSize: 12),
- ),
- if ((user.districtId ?? 0) != 0)
- Padding(
- padding: const EdgeInsets.only(left: 10.0),
- child: Text(
- "${user.province}${user.province == user.city ? '' : user.city}",
- style: TextStyle(color: Colors.white, fontSize: 12),
- ),
- )
- ],
- ),
- constraints: BoxConstraints(minHeight: 30.0),
- ),
- Container(
- width: double.infinity,
- margin: EdgeInsets.all(30.0),
- padding: EdgeInsets.all(6.0),
- child: Center(
- child: Text(
- "累计运动${user.activeDay ?? 0}天,共计${(user.exerRecordSum?.duration ?? 0) ~/ 60}分钟",
- style: Theme.of(context).textTheme.subtitle1!.copyWith(color: Theme.of(context).colorScheme.secondary),
- ),
- ),
- decoration: BoxDecoration(
- gradient: LinearGradient(begin: Alignment.centerLeft, end: Alignment.centerRight, colors: [
- Color(0xFFFFC400).withOpacity(.0),
- Color(0xFFFFC400).withOpacity(.18),
- Color(0xFFFFC400).withOpacity(.0),
- ])),
- ),
- if (selfId != widget.user.id)
- Padding(
- padding: const EdgeInsets.only(top: 5.0),
- child: selfId == '${user.id}'
- ? Container(height: 35)
- : Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
- if(openSocial())
- PrimaryButton(
- width: 120,
- height: 35,
- callback: () {
- // 先尝试换一下
- NavigatorUtil.goPage(context, (context) => UserPostPage(PostUser(id: "${user.id}", name: user.name, avatar: user.avatar, gender: user.gender)));
- // NavigatorUtil.goPage(context, (context) => PrivateMessagePage(user));
- },
- content: '',
- shadow: false,
- child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
- Image.asset("lib/assets/img/mine_icon_message.png"),
- Space(
- width: 6,
- ),
- Text(
- "${widget.user.id == Provider.of<UserModel>(context).user.id.toString() ? '我' : '$_genderLabel'}的帖子",
- strutStyle: fixedLine,
- style: Theme.of(context).textTheme.subtitle1!.copyWith(color: Colors.white),
- )
- ]),
- ),
- if(openSocial())
- Space(
- width: 12,
- ),
- user.isFriend()
- ? GestureDetector(
- child: Container(
- width: 120,
- height: 35,
- alignment: Alignment.center,
- child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
- Image.asset("lib/assets/img/mine_icon_followed.png"),
- Space(
- width: 6,
- ),
- Text(
- "已关注",
- strutStyle: fixedLine,
- style: Theme.of(context).textTheme.subtitle1!.copyWith(color: Theme.of(context).colorScheme.secondary),
- )
- ]),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(20),
- border: Border.all(
- color: Theme.of(context).colorScheme.secondary,
- width: .5,
- ),
- ),
- ),
- onTap: () async {
- await request(context, () async {
- var resp = await model.api.userUnFollow(uid: user.id).catchError((onError) {});
- if (resp.code == 0) {
- user.followStatus = "none";
- widget.userFriends?.firstWhere((element) => element.uid == user.id).isFriends = "0";
- setState(() {});
- ToastUtil.show("取关成功");
- }
- });
- },
- )
- : PrimaryButton(
- width: 120,
- height: 35,
- callback: () async {
- await request(context, () async {
- var resp = await model.api.userFollow(uid: user.id).catchError((onError) {});
- if (resp.code == 0) {
- user.followStatus = "followed";
- var db = widget.userFriends?.firstWhere((element) => element.uid == user.id);
- if (db != null) {
- db.isFriends = "1";
- db.isIgnore = 0;
- }
- setState(() {});
- ToastUtil.show("关注成功");
- }
- });
- },
- content: '',
- shadow: false,
- child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
- Image.asset("lib/assets/img/mine_icon_follow.png"),
- Space(
- width: 6,
- ),
- Text(
- "关注",
- strutStyle: fixedLine,
- style: Theme.of(context).textTheme.subtitle1!.copyWith(color: Colors.white),
- )
- ]),
- ),
- ]),
- ),
- ConstrainedBox(
- constraints: BoxConstraints(minHeight: 200.0),
- child: (user.achievements != null && user.achievements?.isNotEmpty == true) == true
- ? Column(
- children: <Widget>[
- Padding(
- padding: const EdgeInsets.fromLTRB(12.0, 50.0, 12.0, 12.0),
- child: Stack(
- alignment: Alignment.center,
- children: <Widget>[
- Image.asset(
- "lib/assets/img/mine_image_achievement.png",
- fit: BoxFit.fitWidth,
- width: 240,
- ),
- Text(
- "${widget.user.id == Provider.of<UserModel>(context).user.id.toString() ? '我' : '$_genderLabel'}的成就",
- style: Theme.of(context).textTheme.subtitle1!.copyWith(color: Colors.white),
- )
- ],
- ),
- ),
- Padding(
- padding: const EdgeInsets.all(12.0),
- child: Theme(
- child: achievementGroupWidget(user.achievements),
- data: Theme.of(context).copyWith(textTheme: Theme.of(context).textTheme.copyWith(subtitle1: TextStyle(fontSize: 12.0, color: Colors.white, fontWeight: FontWeight.normal, height: 1.1))),
- ),
- ),
- ],
- )
- : Container(),
- )
- ],
- );
- },
- ),
- ),
- ],
- ))),
- ),
- );
- }
- @override
- createModel() => UserDetailModel(widget.user.id.toString());
- }
|