列表的解析和范类使用
对应json类里面的一个类
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/DynamicDetailsComment.dart';
import 'package:music/data/DynamicDetailsData.dart';
import 'package:music/data/GetMomentList.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'Utils/AsperctRaioImage.dart';
import 'PullBlackList.dart';
import 'data/AuthCode.dart';
class DynamicDetails extends StatefulWidget {
int moment_id;
DynamicDetails({key, this.moment_id}) : super(key: key);
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return new Page();
}
}
class Page extends State<DynamicDetails> {
//不知道什么类型就用var
var _items = [];
String Txt = "";
var mBirthday = DateTime.now();
var mBirthdayString = "null";
String _mAvatar = "";
String _mArea = "null";
String _mNickname = "null";
List _photo = [];
bool isSettings = true;
bool canSeeButton = false;
//评论输入控制器
final TextEditingController _commentController = TextEditingController();
//签名焦点
final FocusNode _focusNodeComment = FocusNode();
@override
Widget build(BuildContext context) {
return layout(context);
}
@override
void initState() {
super.initState();
_commentController.addListener(() {
if (_commentController.text.length > 0) {
setState(() {
canSeeButton = true;
});
} else {
setState(() {
canSeeButton = false;
});
}
});
getMomentLists();
}
//关注接口
focus() async {
var apiUrl = "http://47.242.63.216:9527/v1/focus/add";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
//参数
Map map = {};
map["user_id"] = 10003;
//网络请求添加token请求头
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("${result}");
//json解析
Map<String, dynamic> nickname = json.decode(result.toString());
var httpRes = AuthCode.fromJson(nickname);
//如果成功就吐司
if (httpRes.code == 200) {
Fluttertoast.showToast(
msg: "关注成功",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
}
}
//对评论进行点赞
momentLike(var momentId) async {
var apiUrl = "http://47.242.63.216:9527/v1/moment/like";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
//参数
Map map = {};
//昵称从输入框里面获取
map["moment_id"] = momentId;
//网络请求添加token请求头
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("${result}");
//json解析
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);
}
}
//获取该动态列表接口
getMomentLists() async {
var apiUrl = "http://47.242.63.216:9527/v1/moment/getMoment";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
//参数
Map map = {};
//动态ID,0就是最新的
map["moment_id"] = widget.moment_id;
//网络请求添加token请求头
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
log(result.toString());
//json解析
Map<String, dynamic> nickname = json.decode(result.toString());
var httpRes = DynamicDetailsComment.fromJson(nickname);
//如果成功就吐司
if (httpRes.code == 200) {
setState(() {
//将内容赋值给全局变量_items
_items = httpRes.data.commentList;
_mAvatar = httpRes.data.userInfo.avatar;
_mNickname = httpRes.data.userInfo.nickname;
mBirthdayString = StringUtils.getAge(httpRes.data.userInfo.birthday);
_mArea = httpRes.data.userInfo.area;
Txt = httpRes.data.momentInfo.text;
_photo = httpRes.data.momentInfo.photos;
print("图片${_photo}");
print("原来的图片${httpRes.data.momentInfo.photos}");
});
}
}
//评论接口
comment() async {
var apiUrl = "http://47.242.63.216:9527/v1/moment/comment";
SharedPreferences prefs = await SharedPreferences.getInstance();
var tokens = prefs.getString("token");
//参数
Map map = {};
map["moment_id"] = widget.moment_id;
map["parent_common_id"] = 0;
map["text"] = _commentController.text;
//网络请求添加token请求头
Response result = await Dio().post(apiUrl,
data: map, options: Options(headers: {"x-token": tokens}));
debugPrint("${result}");
//json解析
Map<String, dynamic> nickname = json.decode(result.toString());
var httpRes = AuthCode.fromJson(nickname);
//如果成功就吐司
if (httpRes.code == 200) {
_commentController.clear();
Fluttertoast.showToast(
msg: "发布成功",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 10,
backgroundColor: Colors.white,
textColor: Colors.black,
fontSize: 16.0);
}
}
@override
Widget layout(BuildContext context) {
//发动态的文字
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(top: 5, 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: () {
//判断如果点赞就判断自己的ID号好动态列表里面的点赞ID是否相同,有就设置为ture,还有就是为什么图片可以,这边不可以,找一下区别
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: () {},
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(
// width: 200,
// height: 250,
// decoration: BoxDecoration(
// image: DecorationImage(
// image: NetworkImage(photo),
// fit: BoxFit.contain,
// ),
// ),
// );
// }
Widget onePhotoSection(String photo) {
print("${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) {
print("${photo1}");
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 editSection() {
return Row(
children: [
Expanded(
child: Container(
padding: EdgeInsets.only(left: 20, right: 10),
margin: EdgeInsets.only(left: 15, right: 12, bottom: 25),
decoration: BoxDecoration(
color: Color(0xFF2D2D2D),
borderRadius: BorderRadius.circular(50)),
child: TextFormField(
maxLines: 1,
style: const TextStyle(color: Color(0xFFFFFFFF)),
controller: _commentController,
focusNode: _focusNodeComment,
decoration: const InputDecoration(
//去除下划线
border: InputBorder.none,
hintText: "這裡還缺一條你的優質評論",
hintStyle: TextStyle(color: Color(0xFF666666)),
),
),
),
),
Container(
height: 30,
width: 30,
margin: const EdgeInsets.only(bottom: 25, right: 5),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
"assets/base_widgets/icon_dynamic_details_smiley.png"),
fit: BoxFit.fitWidth,
),
),
),
if (canSeeButton)
GestureDetector(
onTap: () {
comment();
_focusNodeComment.unfocus();
},
child: Container(
margin: EdgeInsets.only(left: 5, right: 10, bottom: 25),
padding:
EdgeInsets.only(left: 10, right: 10, top: 5, bottom: 5),
decoration: BoxDecoration(
color: Color(0xFFE6CFA1),
borderRadius: BorderRadius.circular(8)),
child: Text(
"发送",
style: TextStyle(fontSize: 16),
),
),
),
],
);
}
Widget details = Container(
child: Column(
children: [
Container(
//用decoration的BoxDecoration设置圆角
decoration: const BoxDecoration(
//设置背景颜色
color: Color(0xFF1F1F1F),
),
//左图中的第二个红框部分
//边距
margin: const EdgeInsets.only(
left: 15.0,
),
//内边距
padding: 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(_mAvatar),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(50),
),
),
//行的第二个元素,Expanded相当于设置宽度为0,倍数为1,后面的控件就去到最后面了
Expanded(
//Container和Expanded都是只是描述的限制,他们后面的元素都要加child:
//该部分里面是用列排布的
child: Column(
//设置子项左对齐
crossAxisAlignment: CrossAxisAlignment.start,
//Row和Column里面是一堆控件,要用children:[]
children: [
Row(
children: [
Container(
margin: const EdgeInsets.only(bottom: 3),
//第一个元素当作是一个容器,然后设置边距
padding: const EdgeInsets.only(),
//底部添加8像素填充
//列上第一个元素
child: Text(
//第一个元素
_mNickname,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color(0xFFFFFFFF),
fontSize: 17.0),
),
),
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, bottom: 3),
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(mBirthdayString))
],
),
),
Container(
margin: EdgeInsets.only(bottom: 3),
child: Image.asset(
'assets/base_widgets/icon_dynamic_recom_grade.png',
width: 50,
fit: BoxFit.fitWidth,
),
),
],
),
//该行的第一个元素是嵌套的控件,设置一个容器装载
//列上的第二个元素是用行来排列的
Row(
children: [
Container(
margin: EdgeInsets.only(top: 3),
child: const Text(
"粉絲:",
style: TextStyle(
color: Color(0xFF888888),
fontSize: 12,
),
),
),
Container(
margin: EdgeInsets.only(top: 3),
child: Text(
"5",
style: TextStyle(
color: Color(0xFF888888),
fontSize: 12,
fontWeight: FontWeight.bold),
),
),
Container(
margin: EdgeInsets.only(top: 3),
padding: const EdgeInsets.only(left: 40),
child: const Text(
"關注:",
style: TextStyle(
color: Color(0xFF888888),
fontSize: 12,
),
),
),
GestureDetector(
child: Container(
margin: EdgeInsets.only(top: 3),
child: Text(
"899",
style: TextStyle(
color: Color(0xFF888888),
fontSize: 12,
fontWeight: FontWeight.bold),
),
),
),
],
),
],
),
),
// 行的第三个元素
Container(
padding: const EdgeInsets.only(bottom: 8.0), //底部添加8像素填充
child: Column(
children: <Widget>[
GestureDetector(
onTap: () {
// pullBlack(model.userInfo.userId);
focus();
},
// child: Container(
// width: 35.0,
// child: Image.asset(
// "assets/base_widgets/icon_grey_more.png",
// fit: BoxFit.fitWidth,
// )),
child: Container(
margin: EdgeInsets.only(right: 15, top: 15),
padding: EdgeInsets.only(
left: 11, right: 11, top: 7, bottom: 7),
decoration: BoxDecoration(
color: Color(0xFF37AD5E),
borderRadius: BorderRadius.circular(8)),
child: Text(
"+關注",
style: TextStyle(color: Colors.white, fontSize: 12),
),
),
),
//空白文字用来顶位置
Text(''),
],
),
),
],
),
),
dynamicTxtSection(Txt),
if (_photo == null) txtSection(),
if (_photo != null && _photo.length == 1) onePhotoSection(_photo[0]),
if (_photo != null && _photo.length == 2)
twoPhotoSection(_photo[0], _photo[1]),
if (_photo != null && _photo.length == 3)
threePhotoSection(_photo[0], _photo[1], _photo[2]),
if (_photo != null && _photo.length == 4)
fourPhotoSection(_photo[0], _photo[1], _photo[2], _photo[3]),
if (_photo != null && _photo.length == 5)
fivePhotoSection(
_photo[0], _photo[1], _photo[2], _photo[3], _photo[4]),
if (_photo != null && _photo.length == 6)
sixPhotoSection(_photo[0], _photo[1], _photo[2], _photo[3],
_photo[4], _photo[5]),
if (_photo != null && _photo.length == 7)
sevenPhotoSection(_photo[0], _photo[1], _photo[2], _photo[3],
_photo[4], _photo[5], _photo[6]),
if (_photo != null && _photo.length == 8)
eightPhotoSection(_photo[0], _photo[1], _photo[2], _photo[3],
_photo[4], _photo[5], _photo[6], _photo[7]),
if (_photo != null && _photo.length == 9)
ninePhotoSection(_photo[0], _photo[1], _photo[2], _photo[3],
_photo[4], _photo[5], _photo[6], _photo[7], _photo[8]),
placeSection(_mArea),
interactiveSection(widget.moment_id),
//分割线
Container(
margin: const EdgeInsets.only(
top: 5, bottom: 30.0, left: 15, right: 15),
height: 1,
decoration: const BoxDecoration(color: Color(0xFF444444)),
),
],
),
);
//item方法体
Widget itemView(BuildContext context, int index) {
Comment_list model = this._items[index];
return new Column(
children: [
Container(
//用decoration的BoxDecoration设置圆角
decoration: 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相当于设置宽度为0,倍数为1,后面的控件就去到最后面了
Expanded(
//Container和Expanded都是只是描述的限制,他们后面的元素都要加child:
//该部分里面是用列排布的
child: Column(
//设置子项左对齐
crossAxisAlignment: CrossAxisAlignment.start,
//Row和Column里面是一堆控件,要用children:[]
children: [
//该行的第一个元素是嵌套的控件,设置一个容器装载
Container(
margin: EdgeInsets.only(),
//第一个元素当作是一个容器,然后设置边距
padding: EdgeInsets.only(bottom: 8.0),
//底部添加8像素填充
//列上第一个元素
child: Text(
//第一个元素
'${model.userInfo.nickname}',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color(0xFFFFFFFF),
fontSize: 17.0),
),
),
//列上的第二个元素是用行来排列的
Row(
children: [
//每个元素一般都是要加上Container的,因为要设置距离
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: EdgeInsets.only(
top: 3.0, bottom: 3.0, left: 8.0, right: 8.0),
margin:
EdgeInsets.only(left: 10.0, right: 10.0),
decoration: 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), //底部添加8像素填充
child: Column(
children: <Widget>[
GestureDetector(
onTap: () {
// pullBlack(model.userInfo.userId);
focus();
},
child: Container(
margin: EdgeInsets.only(right: 15, top: 15),
padding: EdgeInsets.only(
left: 11, right: 11, top: 7, bottom: 7),
decoration: BoxDecoration(
color: Color(0xFF37AD5E),
borderRadius: BorderRadius.circular(8)),
child: Text(
"+關注",
style: TextStyle(color: Colors.white, fontSize: 12),
),
),
),
//空白文字用来顶位置
Text(''),
],
),
),
],
),
),
dynamicTxtSection(model.comment.text),
placeSection(model.userInfo.area),
interactiveSection(model.comment.momentId),
//分割线
Container(
margin:
EdgeInsets.only(top: 5, bottom: 30.0, left: 15, right: 15),
height: 1,
decoration: const BoxDecoration(color: Color(0xFF444444)),
),
],
);
}
return Material(
child: Scaffold(
appBar: AppBar(
//leading设置状态栏左边的图标
leading: Container(
margin: const EdgeInsets.only(left: 10.0),
width: 20,
child: Image.asset(
'assets/base_widgets/icon_dynamic_notify.png',
fit: BoxFit.fitWidth,
),
),
actions: [
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Container(
width: 50.0,
child: Image.asset(
"assets/base_widgets/icon_grey_more.png",
fit: BoxFit.fitWidth,
)),
),
],
title: Text('動態詳情'),
backgroundColor: Color(0xFF222222),
//文字居中
centerTitle: true,
),
body: Container(
//设置界面背景
decoration: BoxDecoration(
color: Color(0xFF222222),
),
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: [details,ListView.builder(itemCount: _items.length, itemBuilder: itemView, physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,),],
),
)),
editSection(),
],
),
)));
}
}
data json数据
import 'package:json_annotation/json_annotation.dart';
part 'DynamicDetailsComment.g.dart';
@JsonSerializable()
class DynamicDetailsComment extends Object {
@JsonKey(name: 'code')
int code;
@JsonKey(name: 'data')
Data data;
@JsonKey(name: 'msg')
String msg;
DynamicDetailsComment(this.code,this.data,this.msg,);
factory DynamicDetailsComment.fromJson(Map<String, dynamic> srcJson) => _$DynamicDetailsCommentFromJson(srcJson);
Map<String, dynamic> toJson() => _$DynamicDetailsCommentToJson(this);
}
@JsonSerializable()
class Data extends Object {
@JsonKey(name: 'like_state')
bool likeState;
@JsonKey(name: 'focus_state')
bool focusState;
@JsonKey(name: 'moment_info')
Moment_info momentInfo;
@JsonKey(name: 'user_info')
User_info userInfo;
@JsonKey(name: 'comment_list')
List<Comment_list> commentList;
@JsonKey(name: 'like_user_list')
List<dynamic> likeUserList;
Data(this.likeState,this.focusState,this.momentInfo,this.userInfo,this.commentList,this.likeUserList,);
factory Data.fromJson(Map<String, dynamic> srcJson) => _$DataFromJson(srcJson);
Map<String, dynamic> toJson() => _$DataToJson(this);
}
@JsonSerializable()
class Moment_info extends Object {
@JsonKey(name: 'moment_type')
int momentType;
@JsonKey(name: 'moment_id')
int momentId;
@JsonKey(name: 'app_id')
String appId;
@JsonKey(name: 'user_id')
int userId;
@JsonKey(name: 'text')
String text;
@JsonKey(name: 'link')
String link;
@JsonKey(name: 'photos')
List<dynamic> photos;
@JsonKey(name: 'video')
String video;
@JsonKey(name: 'song')
String song;
@JsonKey(name: 'song_name')
String songName;
@JsonKey(name: 'artist')
String artist;
@JsonKey(name: 'show_type')
int showType;
@JsonKey(name: 'create_time')
int createTime;
@JsonKey(name: 'delete_time')
int deleteTime;
@JsonKey(name: 'latitude')
int latitude;
@JsonKey(name: 'longitude')
int longitude;
@JsonKey(name: 'location')
String location;
Moment_info(this.momentType,this.momentId,this.appId,this.userId,this.text,this.link,this.photos,this.video,this.song,this.songName,this.artist,this.showType,this.createTime,this.deleteTime,this.latitude,this.longitude,this.location,);
factory Moment_info.fromJson(Map<String, dynamic> srcJson) => _$Moment_infoFromJson(srcJson);
Map<String, dynamic> toJson() => _$Moment_infoToJson(this);
}
@JsonSerializable()
class User_info extends Object {
@JsonKey(name: 'user_id')
int userId;
@JsonKey(name: 'nickname')
String nickname;
@JsonKey(name: 'sex')
int sex;
@JsonKey(name: 'birthday')
int birthday;
@JsonKey(name: 'area')
String area;
@JsonKey(name: 'sign')
String sign;
@JsonKey(name: 'avatar')
String avatar;
@JsonKey(name: 'avatar_thumb')
String avatarThumb;
User_info(this.userId,this.nickname,this.sex,this.birthday,this.area,this.sign,this.avatar,this.avatarThumb,);
factory User_info.fromJson(Map<String, dynamic> srcJson) => _$User_infoFromJson(srcJson);
Map<String, dynamic> toJson() => _$User_infoToJson(this);
}
@JsonSerializable()
class Comment_list extends Object {
@JsonKey(name: 'comment')
Comment comment;
@JsonKey(name: 'user_info')
User_info1 userInfo;
Comment_list(this.comment,this.userInfo,);
factory Comment_list.fromJson(Map<String, dynamic> srcJson) => _$Comment_listFromJson(srcJson);
Map<String, dynamic> toJson() => _$Comment_listToJson(this);
}
@JsonSerializable()
class Comment extends Object {
@JsonKey(name: 'moment_id')
int momentId;
@JsonKey(name: 'comment_id')
int commentId;
@JsonKey(name: 'parent_comment_id')
int parentCommentId;
@JsonKey(name: 'app_id')
String appId;
@JsonKey(name: 'user_id')
int userId;
@JsonKey(name: 'text')
String text;
@JsonKey(name: 'create_time')
int createTime;
@JsonKey(name: 'delete_time')
int deleteTime;
Comment(this.momentId,this.commentId,this.parentCommentId,this.appId,this.userId,this.text,this.createTime,this.deleteTime,);
factory Comment.fromJson(Map<String, dynamic> srcJson) => _$CommentFromJson(srcJson);
Map<String, dynamic> toJson() => _$CommentToJson(this);
}
@JsonSerializable()
class User_info1 extends Object {
@JsonKey(name: 'user_id')
int userId;
@JsonKey(name: 'nickname')
String nickname;
@JsonKey(name: 'sex')
int sex;
@JsonKey(name: 'birthday')
int birthday;
@JsonKey(name: 'area')
String area;
@JsonKey(name: 'sign')
String sign;
@JsonKey(name: 'avatar')
String avatar;
@JsonKey(name: 'avatar_thumb')
String avatarThumb;
User_info1(this.userId,this.nickname,this.sex,this.birthday,this.area,this.sign,this.avatar,this.avatarThumb,);
factory User_info1.fromJson(Map<String, dynamic> srcJson) => _$User_info1FromJson(srcJson);
Map<String, dynamic> toJson() => _$User_info1ToJson(this);
}