123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- import 'package:flutter/material.dart';
- import 'package:flutter/rendering.dart';
- import 'package:flutter_easyrefresh/easy_refresh.dart';
- import 'package:sport/bean/forum.dart';
- import 'package:sport/bean/post.dart';
- import 'package:sport/bean/post_user.dart';
- import 'package:sport/bean/user_friend.dart';
- import 'package:sport/pages/social/post_widget.dart';
- import 'package:sport/provider/lib/provider_widget.dart';
- import 'package:sport/provider/lib/view_state_lifecycle.dart';
- import 'package:sport/provider/user_detail_model.dart';
- import 'package:sport/services/api/inject_api.dart';
- import 'package:sport/services/userid.dart';
- import 'package:sport/widgets/appbar.dart';
- import 'package:sport/widgets/error.dart';
- import 'package:sport/widgets/image.dart';
- import 'package:sport/widgets/loading.dart';
- import 'package:sport/widgets/misc.dart';
- import 'package:sport/widgets/space.dart';
- class UserPostPage extends StatefulWidget {
- final PostUser user;
- final List<UserFriend>? userFriends;
- UserPostPage(this.user, {this.userFriends});
- @override
- State<StatefulWidget> createState() => _PageState();
- }
- class _PageState extends ViewStateLifecycle<UserPostPage, UserDetailModel> with InjectApi, UserId {
- static const List<String> _sort = ["时间倒序", "点赞最多", "评论最多"];
- String _sortType = _sort[0];
- late ValueNotifier<List<Forum>> _valueNotifierForums;
- @override
- void initState() {
- super.initState();
- _valueNotifierForums = ValueNotifier([]);
- api.getForumIndex().then((value) {
- _valueNotifierForums.value = [Forum(name: "全部")]..addAll(value.results);
- });
- }
- bool isSelf() {
- return selfId == widget.user.id;
- }
- @override
- void dispose() {
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Colors.white,
- appBar: buildAppBar(context,
- title: "${selfId == widget.user.id ? "我" : widget.user.gender == 1 ? "他" : "她"}的帖子",
- actions: [
- ValueListenableBuilder<List<Forum>>(
- builder: (_, snapshot, __) {
- var list = snapshot;
- if (list.isEmpty) return Container();
- return PopupMenuButton(
- onSelected: (v) {
- setState(() {
- if (v is Forum) model.forumBy(v);
- });
- },
- itemBuilder: (BuildContext context) {
- return divideMenus(list.map((e) => menuItemSelected(e, e.gameName ?? "全部", model.forum == e || model.forum == null && e.gameName == "全部")).toList());
- },
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Text(
- model.forum?.gameName ?? "全部",
- style: Theme.of(context).textTheme.bodyText1!,
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(6, 6, 12.0, 6),
- child: arrowBottom(),
- )
- ],
- ),
- );
- },
- valueListenable: _valueNotifierForums,
- ),
- Space(
- width: 12,
- ),
- PopupMenuButton(
- onSelected: (v) {
- setState(() {
- if (v is String) {
- _sortType = v;
- model.sortBy(_sortType);
- }
- });
- },
- itemBuilder: (BuildContext context) {
- return divideMenus(_sort.map((e) => menuItemSelected(e, e, _sortType == e)).toList());
- },
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: <Widget>[
- Text(
- _sortType,
- style: Theme.of(context).textTheme.bodyText1!,
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(6, 6, 12.0, 6),
- child: arrowBottom(),
- )
- ],
- ),
- )
- ]),
- body: ProviderWidget<UserDetailModel>(
- model: model,
- onModelReady: (model) => model.initData(),
- builder: (_, model, __) {
- return EasyRefresh.builder(
- controller: model.refreshController,
- enableControlFinishRefresh: true,
- enableControlFinishLoad: true,
- onRefresh: () => model.refresh(),
- onLoad: model.isIdle ? () => model.loadMore() : null,
- header: buildClassicalHeader(),
- footer: buildClassicalFooter(),
- builder: (context, physics, header, footer) {
- return CustomScrollView(
- physics: physics,
- slivers: <Widget>[
- if (header != null) header,
- if (model.isBusy) SliverToBoxAdapter(child: RequestLoadingWidget()),
- if (model.isEmpty) SliverToBoxAdapter(child: Center(child: RequestErrorWidget(null, msg: "暂无帖子~", assets: RequestErrorWidget.ASSETS_NO_INVITATION))),
- if (model.isIdle)
- SliverList(
- delegate: SliverChildBuilderDelegate(
- (context, index) {
- Post post = model.list[index];
- return PostWidget(
- post,
- model,
- selfId == post.userId,
- jump: false,
- showForum: true,
- showTopButton: true,
- callback: () {
- model.initData();
- },
- );
- // return Text("A");
- },
- childCount: model.list.length,
- ),
- ),
- if (model.isIdle && model.list.isNotEmpty)
- SliverToBoxAdapter(
- child: Center(
- child: Padding(
- padding: const EdgeInsets.all(32.0),
- child: Text("没有更多数据了"),
- )),
- ),
- ],
- );
- });
- }),
- );
- }
- @override
- createModel() => UserDetailModel(widget.user.id.toString());
- }
|