参考一 参考二 首先是关注按键的方法体
Widget _buildRow(itemID) {
print("自己关注的ID列表:${userFocusId},传过来的itemID:${itemID}");
bool alreadySaved = userFocusId
.contains(itemID.toString());
print("真假${alreadySaved}");
return GestureDetector(
onTap: () {
setState(() {
focus(itemID, alreadySaved);
});
setState(() {
});
},
child: Container(
margin: EdgeInsets.only(right: 15, top: 15),
padding: EdgeInsets.only(left: 11, right: 11, top: 7, bottom: 7),
decoration: alreadySaved
? BoxDecoration(
color: Color(0xFF373737),
borderRadius: BorderRadius.circular(8))
: BoxDecoration(
color: Color(0xFF37AD5E),
borderRadius: BorderRadius.circular(8)),
child: alreadySaved
? Text(
"已關注",
style: TextStyle(color: Color(0xFF999999), fontSize: 12),
)
: Text(
"+關注",
style: TextStyle(color: Colors.white, fontSize: 12),
),
));
}
关注接口
focus(id, alreadySaved) async {
var apiUrl = "http://47.242.63.216:9527/v1/focus/";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
Map map = {};
map["user_id"] = id;
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("${result}");
Map<String, dynamic> nickname = json.decode(result.toString());
var httpRes = AuthCode.fromJson(nickname);
if (httpRes.code == 200) {
getFocusListDataMethod();
if (alreadySaved == true) {
setState(() {
});
Fluttertoast.showToast(
msg: "已取消关注",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
} else if (alreadySaved == false) {
setState(() {
});
Fluttertoast.showToast(
msg: "关注成功",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
}
}
}
获取关注接口 List userFocusId = [];
getFocusListDataMethod() async {
var apiUrl = "http://47.242.63.216:9527/v1/focus/";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
Map map = {};
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("${result}");
Map<String, dynamic> nickname = json.decode(result.toString());
var httpRes = GetFocusListData.fromJson(nickname);
print("${httpRes.data.list.length}");
if (httpRes.code == 200) {
userFocusId.clear();
if (httpRes.data.list.length > 0) {
for (int i = 0; i < httpRes.data.list.length; i++) {
userFocusId.add(httpRes.data.list[i].userId.toString());
setState(() {
userFocusId;
});
print("关注的ID${userFocusId.toString()}");
}
}else{
setState(() {
userFocusId;
});
}
}
}
初始化的时候
@override
void initState() {
super.initState();
getMomentLists();
getFocusListDataMethod();
setState(() {
});
}
全部代码
import 'dart:convert';
import 'dart:developer';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:music/Utils/StringUtil.dart';
import 'package:music/data/GetMomentList.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'DynamicDetails.dart';
import 'Utils/AsperctRaioImage.dart';
import 'PullBlackList.dart';
import 'data/AuthCode.dart';
import 'data/GetFocusListData.dart';
class DynamicRecommendNav extends StatefulWidget {
const DynamicRecommendNav({Key key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return new Page();
}
}
class Page extends State<DynamicRecommendNav> {
var _items = [];
bool isSettings = true;
bool focusButton = false;
int _userId = 0;
List<String> userFocusId = [];
@override
Widget build(BuildContext context) {
return layout(context);
}
@override
void initState() {
super.initState();
getMomentLists();
getFocusListDataMethod();
setState(() {
});
}
focus(id, alreadySaved) async {
var apiUrl = "http://47.242.63.216:9527/v1/focus/";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
Map map = {};
map["user_id"] = id;
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("${result}");
Map<String, dynamic> nickname = json.decode(result.toString());
var httpRes = AuthCode.fromJson(nickname);
if (httpRes.code == 200) {
getFocusListDataMethod();
if (alreadySaved == true) {
setState(() {
});
Fluttertoast.showToast(
msg: "已取消关注",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
} else if (alreadySaved == false) {
setState(() {
});
Fluttertoast.showToast(
msg: "关注成功",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
}
}
}
cancelFocus(id) async {
var apiUrl = "http://47.242.63.216:9527/v1/focus/";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
Map map = {};
map["user_id"] = id;
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("${result}");
Map<String, dynamic> nickname = json.decode(result.toString());
var httpRes = AuthCode.fromJson(nickname);
if (httpRes.code == 200) {
getFocusListDataMethod();
Fluttertoast.showToast(
msg: "已取消关注",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
}
}
pullBlack(var id) async {
var apiUrl = "http://47.242.63.216:9527/v1/blacklist/";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
Map map = {};
map["user_id"] = id;
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("${result}");
Map<String, dynamic> blackList = json.decode(result.toString());
var httpRes = AuthCode.fromJson(blackList);
if (httpRes.code == 200) {
Fluttertoast.showToast(
msg: "拉黑或取消拉黑对象:${id}",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const PullBlackList()),
);
}
}
momentLike(var momentId) async {
var apiUrl = "http://47.242.63.216:9527/v1/moment/";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
Map map = {};
map["moment_id"] = momentId;
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("${result}");
Map<String, dynamic> blackList = json.decode(result.toString());
var httpRes = AuthCode.fromJson(blackList);
if (httpRes.code == 200) {
Fluttertoast.showToast(
msg: "点赞:${momentId}",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
}
}
getFocusListDataMethod() async {
var apiUrl = "http://47.242.63.216:9527/v1/focus/";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
Map map = {};
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("${result}");
Map<String, dynamic> nickname = json.decode(result.toString());
var httpRes = GetFocusListData.fromJson(nickname);
print("${httpRes.data.list.length}");
if (httpRes.code == 200) {
userFocusId.clear();
if (httpRes.data.list.length > 0) {
for (int i = 0; i < httpRes.data.list.length; i++) {
userFocusId.add(httpRes.data.list[i].userId.toString());
setState(() {
userFocusId;
});
print("关注的ID${userFocusId.toString()}");
}
}else{
setState(() {
userFocusId;
});
}
}
}
getMomentLists() async {
var apiUrl = "http://47.242.63.216:9527/v1/moment/";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
Map map = {};
map["moment_id"] = 0;
map["page_size"] = 5;
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
log(result.toString());
Map<String, dynamic> nickname = json.decode(result.toString());
var httpRes = GetMomentList.fromJson(nickname);
if (httpRes.code == 200) {
setState(() {
_items = httpRes.data.list;
log(_items.length.toString());
});
}
}
Widget layout(BuildContext context) {
return new Scaffold(
body: Container(
decoration: const BoxDecoration(
color: Color(0xFF1F1F1F),
),
child:
ListView.builder(itemCount: _items.length, itemBuilder: itemView),
),
);
}
Widget layout1(BuildContext context) {
return new Scaffold(
body:
new ListView.builder(
itemCount: _items.length, itemBuilder: itemView1),
);
}
Row dynamicTxtSection(String text) {
return Row(
children: [
Container(
margin: EdgeInsets.only(left: 16, bottom: 5),
child: Text(
text,
style: TextStyle(color: Color(0xFFBBBBBB), fontSize: 16),
),
)
],
);
}
Widget placeSection(String area) {
return Row(
children: [
GestureDetector(
child: Container(
margin: const EdgeInsets.only(left: 15.0),
child: Text(
area,
style: TextStyle(color: Color(0xFF888888)),
),
)),
],
);
}
Widget interactiveSection(int id) {
return Container(
margin: const EdgeInsets.only(top: 25.0, left: 15.0, bottom: 22.0),
child: Row(
children: [
GestureDetector(
onTap: () {
if (1 == 1) {}
setState(() {
getMomentLists();
isSettings = !isSettings;
});
momentLike(id);
},
child: Row(
children: [
Container(
width: 25.0,
child: Image.asset(
isSettings
? "assets/base_widgets/icon_dynamic_recom_like.png"
: "assets/base_widgets/icon_dynamic_liked.png",
fit: BoxFit.fitWidth,
),
),
Container(
margin: const EdgeInsets.only(left: 6.0, right: 24.0),
child: Text(
"996",
style: TextStyle(color: Color(0xFFBBBBBB)),
),
),
],
),
),
GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (BuildContext context) {
return DynamicDetails(
moment_id: id,
);
}));
},
child: Container(
child: Row(
children: [
Container(
width: 25.0,
child: Image.asset(
"assets/base_widgets/icon_dynamic_recom_Comment.png",
fit: BoxFit.fitWidth,
),
),
Container(
margin: const EdgeInsets.only(left: 6.0, right: 24.0),
child: Text(
"65",
style: TextStyle(color: Color(0xFFBBBBBB)),
),
),
],
),
),
),
Container(
width: 25.0,
child: Image.asset(
"assets/base_widgets/icon_dynamic_gift_box.png",
fit: BoxFit.fitWidth,
),
),
Container(
margin: const EdgeInsets.only(left: 6.0, right: 24.0),
child: Text(
"1066",
style: TextStyle(color: Color(0xFFBBBBBB)),
),
)
],
),
);
}
List<String> SONGNAME = [
'音乐1',
'音乐2',
'音乐3',
];
Widget dynamicItem(String name) {
return Column(
mainAxisSize: MainAxisSize.max,
children: [
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
color: Colors.grey[300],
image: DecorationImage(
image: NetworkImage(
"https://www.itying.com/images/flutter/3.png"),
fit: BoxFit.fill),
borderRadius: BorderRadius.circular(10)),
margin: const EdgeInsets.only(left: 15.0, bottom: 12.0),
),
],
);
}
Widget dynamicListSection() {
return SizedBox(
height: 130,
child: ListView(
scrollDirection: Axis.horizontal,
children: SONGNAME.map((city) => dynamicItem(city)).toList(),
),
);
}
Widget onePhotoSection(String photo) {
return Container(
child:
AsperctRaioImage.network(photo, builder: (context, snapshot, url) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 16, right: 16, bottom: 5),
width: snapshot.data.width.toDouble() / 10,
height: snapshot.data.height.toDouble() / 10,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(url),
fit: BoxFit.contain,
),
),
)
],
);
}));
}
Widget twoPhotoSection(String photo1, String photo2) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
width: 110,
height: 110,
margin: EdgeInsets.only(left: 70, right: 10),
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo1),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo2),
fit: BoxFit.cover,
),
),
)
],
);
}
Widget threePhotoSection(String photo1, String photo2, String photo3) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 110,
height: 110,
margin: EdgeInsets.only(left: 10, right: 10),
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo1),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo2),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo3),
fit: BoxFit.cover,
),
),
)
],
);
}
Widget fourPhotoSection(
String photo1, String photo2, String photo3, String photo4) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
color: Colors.white,
image: DecorationImage(
image: NetworkImage(photo1),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo2),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo3),
fit: BoxFit.cover,
),
),
),
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo4),
fit: BoxFit.cover,
),
),
)
],
)
],
);
}
Widget fivePhotoSection(String photo1, String photo2, String photo3,
String photo4, String photo5) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo1),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo2),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo3),
fit: BoxFit.cover,
),
),
),
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo4),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo5),
fit: BoxFit.cover,
),
),
)
],
)
],
);
}
Widget sixPhotoSection(String photo1, String photo2, String photo3,
String photo4, String photo5, String photo6) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo1),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo2),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo3),
fit: BoxFit.cover,
),
),
),
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo4),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo5),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo6),
fit: BoxFit.cover,
),
),
)
],
)
],
);
}
Widget sevenPhotoSection(String photo1, String photo2, String photo3,
String photo4, String photo5, String photo6, String photo7) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo1),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo2),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo3),
fit: BoxFit.cover,
),
),
),
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo4),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo5),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo6),
fit: BoxFit.cover,
),
),
)
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo7),
fit: BoxFit.cover,
),
),
),
],
)
],
);
}
Widget eightPhotoSection(
String photo1,
String photo2,
String photo3,
String photo4,
String photo5,
String photo6,
String photo7,
String photo8) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo1),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo2),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo3),
fit: BoxFit.cover,
),
),
),
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo4),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo5),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo6),
fit: BoxFit.cover,
),
),
)
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo7),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo8),
fit: BoxFit.cover,
),
),
),
],
)
],
);
}
Widget ninePhotoSection(
String photo1,
String photo2,
String photo3,
String photo4,
String photo5,
String photo6,
String photo7,
String photo8,
String photo9) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo1),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo2),
fit: BoxFit.cover,
),
),
),
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo3),
fit: BoxFit.cover,
),
),
),
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo4),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo5),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo6),
fit: BoxFit.cover,
),
),
)
],
),
Row(
children: [
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo7),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo8),
fit: BoxFit.cover,
),
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10, bottom: 5),
width: 110,
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(photo9),
fit: BoxFit.cover,
),
),
),
],
)
],
);
}
Widget txtSection() {
return Container(
child: Text(""),
);
}
Widget _buildRow(itemID) {
print("自己关注的ID列表:${userFocusId},传过来的itemID:${itemID}");
bool alreadySaved = userFocusId
.contains(itemID.toString());
print("真假${alreadySaved}");
return GestureDetector(
onTap: () {
setState(() {
focus(itemID, alreadySaved);
});
setState(() {
});
},
child: Container(
margin: EdgeInsets.only(right: 15, top: 15),
padding: EdgeInsets.only(left: 11, right: 11, top: 7, bottom: 7),
decoration: alreadySaved
? BoxDecoration(
color: Color(0xFF373737),
borderRadius: BorderRadius.circular(8))
: BoxDecoration(
color: Color(0xFF37AD5E),
borderRadius: BorderRadius.circular(8)),
child: alreadySaved
? Text(
"已關注",
style: TextStyle(color: Color(0xFF999999), fontSize: 12),
)
: Text(
"+關注",
style: TextStyle(color: Colors.white, fontSize: 12),
),
));
}
Widget dynamicListSection2() {
return SizedBox(
height: 130,
child: ListView(
scrollDirection: Axis.horizontal,
children: SONGNAME.map((city) => dynamicItem(city)).toList(),
),
);
}
Widget itemView(BuildContext context, int index) {
List1 model = this._items[index];
_userId = model.momentInfo.userId;
return new Column(
children: [
Container(
decoration: const BoxDecoration(
color: Color(0xFF1F1F1F),
),
margin: const EdgeInsets.only(
left: 15.0,
),
padding: const EdgeInsets.only(bottom: 10.0),
child: Row(
children: [
Container(
width: 50,
height: 50,
margin: EdgeInsets.only(right: 15.0),
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(model.userInfo.avatar),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(50),
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(),
padding: const EdgeInsets.only(bottom: 8.0),
child: Text(
'${model.userInfo.nickname}',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color(0xFFFFFFFF),
fontSize: 17.0),
),
),
Row(
children: [
Container(
padding: const EdgeInsets.only(
left: 8.0, right: 8.0, top: 3.0, bottom: 3.0),
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0),
bottomLeft: Radius.circular(10.0),
bottomRight: Radius.circular(10.0)),
color: const Color(0xFFBBA57A),
border: Border.all(
width: 1, color: const Color(0xFFBBA57A)),
),
child: const Text(
'認證歌手',
style: TextStyle(
color: Color(0xFF1F1F1F),
fontSize: 12,
fontWeight: FontWeight.bold),
),
),
Container(
padding: const EdgeInsets.only(
top: 3.0, bottom: 3.0, left: 8.0, right: 8.0),
margin:
const EdgeInsets.only(left: 10.0, right: 10.0),
decoration: const BoxDecoration(
color: Color(0xFFBBBBBB),
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
child: Row(
children: [
Image.asset(
'assets/base_widgets/icon_dynamic_recom_male.png',
width: 13,
fit: BoxFit.fitWidth,
),
Container(
margin: const EdgeInsets.only(left: 5.0),
child: Text(StringUtils.getAge(
model.userInfo.birthday)))
],
),
),
Container(
child: Image.asset(
'assets/base_widgets/icon_dynamic_recom_grade.png',
width: 50,
fit: BoxFit.fitWidth,
),
),
],
),
],
),
),
Container(
padding: const EdgeInsets.only(bottom: 8.0),
child: Column(
children: <Widget>[
_buildRow(model.userInfo.userId),
Text(''),
],
),
),
],
),
),
dynamicTxtSection(model.momentInfo.text),
if (model.momentInfo.photos == null) txtSection(),
if (model.momentInfo.photos != null &&
model.momentInfo.photos.length == 1)
onePhotoSection(model.momentInfo.photos[0]),
if (model.momentInfo.photos != null &&
model.momentInfo.photos.length == 2)
twoPhotoSection(
model.momentInfo.photos[0], model.momentInfo.photos[1]),
if (model.momentInfo.photos != null &&
model.momentInfo.photos.length == 3)
threePhotoSection(model.momentInfo.photos[0],
model.momentInfo.photos[1], model.momentInfo.photos[2]),
if (model.momentInfo.photos != null &&
model.momentInfo.photos.length == 4)
fourPhotoSection(
model.momentInfo.photos[0],
model.momentInfo.photos[1],
model.momentInfo.photos[2],
model.momentInfo.photos[3]),
if (model.momentInfo.photos != null &&
model.momentInfo.photos.length == 5)
fivePhotoSection(
model.momentInfo.photos[0],
model.momentInfo.photos[1],
model.momentInfo.photos[2],
model.momentInfo.photos[3],
model.momentInfo.photos[4]),
if (model.momentInfo.photos != null &&
model.momentInfo.photos.length == 6)
sixPhotoSection(
model.momentInfo.photos[0],
model.momentInfo.photos[1],
model.momentInfo.photos[2],
model.momentInfo.photos[3],
model.momentInfo.photos[4],
model.momentInfo.photos[5]),
if (model.momentInfo.photos != null &&
model.momentInfo.photos.length == 7)
sevenPhotoSection(
model.momentInfo.photos[0],
model.momentInfo.photos[1],
model.momentInfo.photos[2],
model.momentInfo.photos[3],
model.momentInfo.photos[4],
model.momentInfo.photos[5],
model.momentInfo.photos[6]),
if (model.momentInfo.photos != null &&
model.momentInfo.photos.length == 8)
eightPhotoSection(
model.momentInfo.photos[0],
model.momentInfo.photos[1],
model.momentInfo.photos[2],
model.momentInfo.photos[3],
model.momentInfo.photos[4],
model.momentInfo.photos[5],
model.momentInfo.photos[6],
model.momentInfo.photos[7]),
if (model.momentInfo.photos != null &&
model.momentInfo.photos.length == 9)
ninePhotoSection(
model.momentInfo.photos[0],
model.momentInfo.photos[1],
model.momentInfo.photos[2],
model.momentInfo.photos[3],
model.momentInfo.photos[4],
model.momentInfo.photos[5],
model.momentInfo.photos[6],
model.momentInfo.photos[7],
model.momentInfo.photos[8]),
placeSection(model.userInfo.area),
interactiveSection(model.momentInfo.momentId),
Container(
margin:
const EdgeInsets.only(top: 5, bottom: 30.0, left: 15, right: 15),
height: 1,
decoration: const BoxDecoration(color: Color(0xFF444444)),
),
],
);
}
Widget itemView1(BuildContext context, int index) {
List1 model = this._items[index];
return new Container(
color: Color.fromARGB(0x22, 0x49, 0xa9, 0x8d),
child: new Padding(
padding: const EdgeInsets.all(8.0),
child: new Padding(
padding: const EdgeInsets.all(8.0),
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Text(
'${model.momentInfo.userId}年${model.userInfo.userId}月',
style: new TextStyle(fontSize: 15.0)),
new Text('(${model.userInfo.userId})',
style: new TextStyle(fontSize: 15.0)),
],
),
new Center(
heightFactor: 6.0,
child: new Text("${model.userInfo.userId}",
style: new TextStyle(fontSize: 17.0)),
)
],
))));
}
}
还有就是点赞
Widget interactiveSection(int id,likeStates) {
print("点赞的真假${likeStates}");
bool likeState=likeStates;
return Container(
margin: EdgeInsets.only(top: 25.0, left: 15.0, bottom: 22.0),
child: Row(
children: [
GestureDetector(
onTap: () {
momentLike(id,likeState);
},
child: Row(
children: [
Container(
width: 25.0,
child: Image.asset(
likeState
? "assets/base_widgets/icon_dynamic_liked.png"
: "assets/base_widgets/icon_dynamic_recom_like.png",
fit: BoxFit.fitWidth,
),
),
Container(
margin: EdgeInsets.only(left: 6.0, right: 24.0),
child: Text(
"996",
style: TextStyle(color: Color(0xFFBBBBBB)),
),
),
],
),
),
GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (BuildContext context) {
return DynamicDetails(
moment_id: id,
);
}));
},
child: Container(
child: Row(
children: [
Container(
width: 25.0,
child: Image.asset(
"assets/base_widgets/icon_dynamic_recom_Comment.png",
fit: BoxFit.fitWidth,
),
),
Container(
margin: const EdgeInsets.only(left: 6.0, right: 24.0),
child: Text(
"65",
style: TextStyle(color: Color(0xFFBBBBBB)),
),
),
],
),
),
),
Container(
width: 25.0,
child: Image.asset(
"assets/base_widgets/icon_dynamic_gift_box.png",
fit: BoxFit.fitWidth,
),
),
Container(
margin: const EdgeInsets.only(left: 6.0, right: 24.0),
child: Text(
"1066",
style: TextStyle(color: Color(0xFFBBBBBB)),
),
)
],
),
);
}
点赞接口如下
momentLike(var momentId,likeState) async {
var apiUrl = "http://47.242.63.216:9527/v1/moment/";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
Map map = {};
map["moment_id"] = momentId;
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("点赞列表${result}");
Map<String, dynamic> blackList = json.decode(result.toString());
var httpRes = AuthCode.fromJson(blackList);
if (httpRes.code == 200) {
if(likeState){
setState(() {
getMomentLists();
});
Fluttertoast.showToast(
msg: "已取消点赞",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
}else{
setState(() {
getMomentLists();
});
Fluttertoast.showToast(
msg: "点赞成功",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
}
}
}
|