|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart'; |
| 3 | +import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart'; |
| 4 | +import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart'; |
| 5 | +import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart'; |
| 6 | +import 'package:gsy_github_app_flutter/widget/GSYIConText.dart'; |
| 7 | + |
| 8 | +/** |
| 9 | + * Issue 详情头 |
| 10 | + * Created by guoshuyu |
| 11 | + * on 2018/7/21. |
| 12 | + */ |
| 13 | + |
| 14 | +class IssueHeaderItem extends StatelessWidget { |
| 15 | + final IssueHeaderViewModel issueHeaderViewModel; |
| 16 | + |
| 17 | + final VoidCallback onPressed; |
| 18 | + |
| 19 | + IssueHeaderItem(this.issueHeaderViewModel, {this.onPressed}); |
| 20 | + |
| 21 | + @override |
| 22 | + Widget build(BuildContext context) { |
| 23 | + Color issueStateColor = issueHeaderViewModel.state == "open" ? Colors.green : Colors.red; |
| 24 | + Widget bottomContainer = new Row( |
| 25 | + children: <Widget>[ |
| 26 | + new GSYIConText( |
| 27 | + GSYICons.ISSUE_ITEM_ISSUE, |
| 28 | + issueHeaderViewModel.state, |
| 29 | + TextStyle( |
| 30 | + color: issueStateColor, |
| 31 | + fontSize: GSYConstant.smallTextSize, |
| 32 | + ), |
| 33 | + issueStateColor, |
| 34 | + 15.0, |
| 35 | + padding: 2.0, |
| 36 | + ), |
| 37 | + new Padding(padding: new EdgeInsets.all(2.0)), |
| 38 | + new Text(issueHeaderViewModel.issueTag, style: GSYConstant.smallTextWhite), |
| 39 | + new Padding(padding: new EdgeInsets.all(2.0)), |
| 40 | + new GSYIConText( |
| 41 | + GSYICons.ISSUE_ITEM_COMMENT, |
| 42 | + issueHeaderViewModel.commentCount, |
| 43 | + GSYConstant.smallTextWhite, |
| 44 | + Color(GSYColors.white), |
| 45 | + 15.0, |
| 46 | + padding: 2.0, |
| 47 | + ), |
| 48 | + ], |
| 49 | + ); |
| 50 | + return new GSYCardItem( |
| 51 | + color: Color(GSYColors.primaryValue), |
| 52 | + child: new FlatButton( |
| 53 | + padding: new EdgeInsets.all(0.0), |
| 54 | + onPressed: onPressed, |
| 55 | + child: new Padding( |
| 56 | + padding: new EdgeInsets.all(10.0), |
| 57 | + child: new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[ |
| 58 | + new IconButton( |
| 59 | + icon: new ClipOval( |
| 60 | + child: new FadeInImage.assetNetwork( |
| 61 | + placeholder: "static/images/logo.png", |
| 62 | + //预览图 |
| 63 | + fit: BoxFit.fitWidth, |
| 64 | + image: issueHeaderViewModel.actionUserPic, |
| 65 | + width: 80.0, |
| 66 | + height: 80.0, |
| 67 | + ), |
| 68 | + ), |
| 69 | + onPressed: () { |
| 70 | + NavigatorUtils.goPerson(context, issueHeaderViewModel.actionUser); |
| 71 | + }), |
| 72 | + new Expanded( |
| 73 | + child: Column( |
| 74 | + mainAxisSize: MainAxisSize.min, |
| 75 | + children: <Widget>[ |
| 76 | + new Row( |
| 77 | + children: <Widget>[ |
| 78 | + new Expanded(child: new Text(issueHeaderViewModel.actionUser, style: GSYConstant.normalTextWhite)), |
| 79 | + new Text( |
| 80 | + issueHeaderViewModel.actionTime, |
| 81 | + style: GSYConstant.subSmallText, |
| 82 | + maxLines: 2, |
| 83 | + overflow: TextOverflow.ellipsis, |
| 84 | + ), |
| 85 | + ], |
| 86 | + ), |
| 87 | + new Padding(padding: new EdgeInsets.all(2.0)), |
| 88 | + bottomContainer, |
| 89 | + new Container( |
| 90 | + child: new Text( |
| 91 | + issueHeaderViewModel.issueComment, |
| 92 | + style: GSYConstant.smallTextWhite, |
| 93 | + maxLines: 2, |
| 94 | + ), |
| 95 | + margin: new EdgeInsets.only(top: 6.0, bottom: 2.0), |
| 96 | + alignment: Alignment.topLeft), |
| 97 | + new Padding( |
| 98 | + padding: new EdgeInsets.only(left: 0.0, top: 2.0, right: 0.0, bottom: 0.0), |
| 99 | + ), |
| 100 | + ], |
| 101 | + ), |
| 102 | + ), |
| 103 | + ]), |
| 104 | + ), |
| 105 | + ), |
| 106 | + ); |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +class IssueHeaderViewModel { |
| 111 | + String actionTime = "---"; |
| 112 | + String actionUser = "---"; |
| 113 | + String actionUserPic = "---"; |
| 114 | + String closed_by = "---"; |
| 115 | + bool locked = false; |
| 116 | + String issueComment = "---"; |
| 117 | + String issueDesHtml = "---"; |
| 118 | + String commentCount = "---"; |
| 119 | + String state = "---"; |
| 120 | + String issueDes = "---"; |
| 121 | + String issueTag = "---"; |
| 122 | + |
| 123 | + IssueHeaderViewModel(); |
| 124 | + |
| 125 | + IssueHeaderViewModel.fromMap(issueMap) { |
| 126 | + actionTime = CommonUtils.getNewsTimeStr(DateTime.parse(issueMap["created_at"])); |
| 127 | + actionUser = issueMap["user"]["login"]; |
| 128 | + actionUserPic = issueMap["user"]["avatar_url"]; |
| 129 | + closed_by = issueMap["closed_by"] != null ? issueMap["closed_by"]["login"] : ""; |
| 130 | + locked = issueMap["locked"]; |
| 131 | + issueComment = issueMap["title"]; |
| 132 | + issueDesHtml = issueMap["body_html"] != null ? issueMap["body_html"] : ""; |
| 133 | + commentCount = issueMap["comments"].toString() + ""; |
| 134 | + state = issueMap["state"]; |
| 135 | + issueDes = issueMap["body"] != null ? ": \n" + issueMap["body"] : ''; |
| 136 | + issueTag = "#" + issueMap["number"].toString(); |
| 137 | + } |
| 138 | +} |
0 commit comments