对接关注话题接口

master
laiiihz 5 years ago
parent fbc1a5bde6
commit bf3968aa60

@ -411,4 +411,7 @@ class LiveAPI {
///
static const String cancelTopic = '/v1/live/topic/follow/cancel';
///
static const String topicContentList = '/v1/live/topic/content/list';
}

@ -0,0 +1,52 @@
class TopicContentListModel {
int userId;
String nickname;
String headImgUrl;
String content;
String coverUrl;
int trendId;
int originId;
int trendType;
int praise;
int isPraise;
TopicContentListModel(
{this.userId,
this.nickname,
this.headImgUrl,
this.content,
this.coverUrl,
this.trendId,
this.originId,
this.trendType,
this.praise,
this.isPraise});
TopicContentListModel.fromJson(Map<String, dynamic> json) {
userId = json['userId'];
nickname = json['nickname'];
headImgUrl = json['headImgUrl'];
content = json['content'];
coverUrl = json['coverUrl'];
trendId = json['trendId'];
originId = json['originId'];
trendType = json['trendType'];
praise = json['praise'];
isPraise = json['isPraise'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['userId'] = this.userId;
data['nickname'] = this.nickname;
data['headImgUrl'] = this.headImgUrl;
data['content'] = this.content;
data['coverUrl'] = this.coverUrl;
data['trendId'] = this.trendId;
data['originId'] = this.originId;
data['trendType'] = this.trendType;
data['praise'] = this.praise;
data['isPraise'] = this.isPraise;
return data;
}
}

@ -1,4 +1,3 @@
import 'dart:math';
import 'dart:ui';
import 'package:flutter/material.dart';
@ -6,9 +5,11 @@ import 'package:recook/constants/api.dart';
import 'package:recook/constants/header.dart';
import 'package:recook/manager/http_manager.dart';
import 'package:recook/pages/live/models/topic_base_info_model.dart';
import 'package:recook/pages/live/models/topic_content_list_model.dart';
import 'package:recook/pages/live/widget/live_attention_button.dart';
import 'package:recook/widgets/custom_image_button.dart';
import 'package:recook/widgets/recook_back_button.dart';
import 'package:recook/widgets/refresh_widget.dart';
import 'package:waterfall_flow/waterfall_flow.dart';
class TopicPage extends StatefulWidget {
@ -21,6 +22,9 @@ class TopicPage extends StatefulWidget {
class _TopicPageState extends State<TopicPage> {
TopicBaseInfoModel _topicBaseInfoModel = TopicBaseInfoModel.zero();
GSRefreshController _controller = GSRefreshController();
int _page = 1;
List<TopicContentListModel> models = [];
@override
void initState() {
super.initState();
@ -34,118 +38,131 @@ class _TopicPageState extends State<TopicPage> {
});
}
@override
void dispose() {
_controller?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColor.frenchColor,
body: Stack(
children: [
CustomScrollView(
physics:
BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
slivers: [
SliverAppBar(
leading: RecookBackButton(white: true),
brightness: Brightness.light,
stretch: true,
floating: true,
expandedHeight:
rSize(140) + MediaQuery.of(context).viewPadding.top,
flexibleSpace: FlexibleSpaceBar(
background: Stack(
children: [
Positioned(
left: 0,
right: 0,
bottom: 0,
top: 0,
child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_PLACEHOLDER_NEW_1X1_A_PNG,
image: Api.getImgUrl(_topicBaseInfoModel.topicImg),
fit: BoxFit.cover,
NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
SliverAppBar(
leading: RecookBackButton(white: true),
brightness: Brightness.light,
stretch: true,
floating: true,
expandedHeight:
rSize(140) + MediaQuery.of(context).viewPadding.top,
flexibleSpace: FlexibleSpaceBar(
background: Stack(
children: [
Positioned(
left: 0,
right: 0,
bottom: 0,
top: 0,
child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_PLACEHOLDER_NEW_1X1_A_PNG,
image: Api.getImgUrl(_topicBaseInfoModel.topicImg),
fit: BoxFit.cover,
),
),
),
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
color: Colors.black.withOpacity(0.11),
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
color: Colors.black.withOpacity(0.11),
),
),
),
Positioned(
bottom: rSize(22),
left: rSize(15),
right: rSize(15),
child: Row(
children: [
FadeInImage.assetNetwork(
placeholder: R.ASSETS_PLACEHOLDER_NEW_1X1_A_PNG,
image:
Api.getImgUrl(_topicBaseInfoModel.topicImg),
fit: BoxFit.cover,
height: rSize(64),
width: rSize(64),
alignment: Alignment.bottomRight,
),
SizedBox(width: rSize(15)),
Expanded(
child: Column(
children: [
Row(
children: [
Expanded(
child: Text(
'#${_topicBaseInfoModel.title}',
style: TextStyle(
color: Colors.white,
fontSize: rSP(16),
Positioned(
bottom: rSize(22),
left: rSize(15),
right: rSize(15),
child: Row(
children: [
FadeInImage.assetNetwork(
placeholder: R.ASSETS_PLACEHOLDER_NEW_1X1_A_PNG,
image:
Api.getImgUrl(_topicBaseInfoModel.topicImg),
fit: BoxFit.cover,
height: rSize(64),
width: rSize(64),
alignment: Alignment.bottomRight,
),
SizedBox(width: rSize(15)),
Expanded(
child: Column(
children: [
Row(
children: [
Expanded(
child: Text(
'#${_topicBaseInfoModel.title}',
style: TextStyle(
color: Colors.white,
fontSize: rSP(16),
),
),
),
),
LiveAttentionButton(
initAttention:
_topicBaseInfoModel.isFollow == 1,
filled: true,
width: rSize(56),
height: rSize(26),
onAttention: (oldAttentionState) {
HttpManager.post(
oldAttentionState
? LiveAPI.cancelTopic
: LiveAPI.addTopic,
{'topicId': widget.topicId},
);
},
),
],
),
],
LiveAttentionButton(
initAttention:
_topicBaseInfoModel.isFollow == 1,
filled: true,
width: rSize(56),
height: rSize(26),
onAttention: (oldAttentionState) {
HttpManager.post(
oldAttentionState
? LiveAPI.cancelTopic
: LiveAPI.addTopic,
{'topicId': widget.topicId},
);
},
),
],
),
],
),
),
),
],
],
),
),
),
],
],
),
),
),
),
SliverPadding(
];
},
body: RefreshWidget(
controller: _controller,
onRefresh: () {
_page = 1;
_getTopicContentModels().then((getModels) {
models = getModels;
if (mounted) setState(() {});
_controller.refreshCompleted();
});
},
body: WaterfallFlow.builder(
padding: EdgeInsets.all(rSize(15)),
sliver: SliverWaterfallFlow(
delegate: SliverChildBuilderDelegate(
(context, index) {
return _buildCard();
},
// childCount:
),
gridDelegate:
SliverWaterfallFlowDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: rSize(15),
mainAxisSpacing: rSize(15),
),
gridDelegate:
SliverWaterfallFlowDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: rSize(15),
mainAxisSpacing: rSize(15),
),
itemBuilder: (context, index) {
return _buildCard(models[index]);
},
itemCount: models.length,
),
],
),
),
Positioned(
bottom: MediaQuery.of(context).viewPadding.bottom,
@ -177,30 +194,29 @@ class _TopicPageState extends State<TopicPage> {
);
}
_buildCard() {
final height = 100 + 150 * Random().nextDouble();
_buildCard(TopicContentListModel model) {
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: CustomImageButton(
borderRadius: BorderRadius.circular(rSize(10)),
child: MaterialButton(
padding: EdgeInsets.zero,
color: Colors.white,
onPressed: () {},
splashColor: Colors.black26,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
height: height,
decoration: BoxDecoration(
color: Colors.white,
),
child: Placeholder(),
FadeInImage.assetNetwork(
placeholder: R.ASSETS_PLACEHOLDER_NEW_1X1_A_PNG,
image: model.coverUrl,
),
Container(
color: Colors.white,
padding: EdgeInsets.all(rSize(10)),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'爱生活,爱厨房,爱上厨房精美的器具里生活的…',
model.content,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@ -212,12 +228,21 @@ class _TopicPageState extends State<TopicPage> {
SizedBox(height: rSize(6)),
Row(
children: [
CircleAvatar(
radius: rSize(9),
ClipRRect(
borderRadius: BorderRadius.circular(9),
child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_PLACEHOLDER_NEW_1X1_A_PNG,
image: Api.getImgUrl(model.headImgUrl),
height: rSize(18),
width: rSize(18),
),
),
rWBox(4),
Expanded(
child: Text(
'',
model.nickname,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Color(0xFF666666),
fontSize: rSP(12),
@ -230,7 +255,7 @@ class _TopicPageState extends State<TopicPage> {
width: rSize(14),
),
Text(
'13',
model.praise.toString(),
style: TextStyle(
color: Color(0xFf666666),
fontSize: rSP(12),
@ -246,4 +271,18 @@ class _TopicPageState extends State<TopicPage> {
),
);
}
Future<List<TopicContentListModel>> _getTopicContentModels() async {
ResultData resultData = await HttpManager.post(LiveAPI.topicContentList, {
'topicId': widget.topicId,
'page': _page,
'limit': 12,
});
if (resultData?.data['data']['list'] == null)
return [];
else
return (resultData.data['data']['list'] as List)
.map((e) => TopicContentListModel.fromJson(e))
.toList();
}
}

@ -98,7 +98,10 @@ class _UserAttentionViewState extends State<UserAttentionView>
onTap: () {
CRoute.push(
context,
UserHomePage(userId: model.userId),
UserHomePage(
userId: model.userId,
initAttention: model.isFollow == 1,
),
);
},
onAttention: (bool oldState) {

@ -19,7 +19,9 @@ import 'package:recook/widgets/recook_indicator.dart';
class UserHomePage extends StatefulWidget {
final int userId;
UserHomePage({Key key, @required this.userId}) : super(key: key);
final bool initAttention;
UserHomePage({Key key, @required this.userId, this.initAttention = false})
: super(key: key);
@override
_UserHomePageState createState() => _UserHomePageState();
@ -122,7 +124,7 @@ class _UserHomePageState extends State<UserHomePage>
: LiveAttentionButton(
filled: true,
rounded: false,
initAttention: false,
initAttention: widget.initAttention,
width: rSize(68),
height: rSize(30),
onAttention: (oldAttentionState) {},

Loading…
Cancel
Save