|
| 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相关item |
| 10 | + * Created by guoshuyu |
| 11 | + * Date: 2018-07-19 |
| 12 | + */ |
| 13 | +class IssueItem extends StatelessWidget { |
| 14 | + final IssueItemViewModel issueItemViewModel; |
| 15 | + |
| 16 | + final VoidCallback onPressed; |
| 17 | + |
| 18 | + final bool needBottom; |
| 19 | + |
| 20 | + IssueItem(this.issueItemViewModel, {this.onPressed, this.needBottom = false}); |
| 21 | + |
| 22 | + @override |
| 23 | + Widget build(BuildContext context) { |
| 24 | + Widget bottomContainer = (needBottom) |
| 25 | + ? new Container() |
| 26 | + : new Row( |
| 27 | + children: <Widget>[ |
| 28 | + new GSYIConText( |
| 29 | + GSYICons.ISSUE_ITEM_ISSUE, |
| 30 | + issueItemViewModel.state, |
| 31 | + GSYConstant.subSmallText, |
| 32 | + issueItemViewModel.state == "open" ? Colors.green : Colors.red, |
| 33 | + 15.0, |
| 34 | + padding: 2.0, |
| 35 | + ), |
| 36 | + new Padding(padding: new EdgeInsets.all(2.0)), |
| 37 | + new Expanded( |
| 38 | + child: new Text(issueItemViewModel.issueTag, style: GSYConstant.subSmallText), |
| 39 | + ), |
| 40 | + new GSYIConText( |
| 41 | + GSYICons.ISSUE_ITEM_COMMENT, |
| 42 | + issueItemViewModel.commentCount, |
| 43 | + GSYConstant.subSmallText, |
| 44 | + Color(GSYColors.subTextColor), |
| 45 | + 15.0, |
| 46 | + padding: 2.0, |
| 47 | + ), |
| 48 | + ], |
| 49 | + ); |
| 50 | + return new GSYCardItem( |
| 51 | + child: new FlatButton( |
| 52 | + padding: new EdgeInsets.all(0.0), |
| 53 | + onPressed: onPressed, |
| 54 | + child: new Padding( |
| 55 | + padding: new EdgeInsets.only(left: 5.0, top: 5.0, right: 10.0, bottom: 8.0), |
| 56 | + child: new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[ |
| 57 | + new IconButton( |
| 58 | + icon: new ClipOval( |
| 59 | + child: new FadeInImage.assetNetwork( |
| 60 | + placeholder: "static/images/logo.png", |
| 61 | + //预览图 |
| 62 | + fit: BoxFit.fitWidth, |
| 63 | + image: issueItemViewModel.actionUserPic, |
| 64 | + width: 30.0, |
| 65 | + height: 30.0, |
| 66 | + ), |
| 67 | + ), |
| 68 | + onPressed: () {}), |
| 69 | + new Expanded( |
| 70 | + child: Column( |
| 71 | + mainAxisSize: MainAxisSize.min, |
| 72 | + children: <Widget>[ |
| 73 | + new Row( |
| 74 | + children: <Widget>[ |
| 75 | + new Expanded(child: new Text(issueItemViewModel.actionUser, style: GSYConstant.smallTextBold)), |
| 76 | + new Text( |
| 77 | + issueItemViewModel.actionTime, |
| 78 | + style: GSYConstant.subSmallText, |
| 79 | + maxLines: 2, |
| 80 | + overflow: TextOverflow.ellipsis, |
| 81 | + ), |
| 82 | + ], |
| 83 | + ), |
| 84 | + new Padding( |
| 85 | + padding: new EdgeInsets.only(left: 0.0, top: 2.0, right: 0.0, bottom: 0.0), |
| 86 | + ), |
| 87 | + new Container( |
| 88 | + child: new Text( |
| 89 | + issueItemViewModel.issueComment, |
| 90 | + style: GSYConstant.smallTextBold, |
| 91 | + maxLines: 2, |
| 92 | + ), |
| 93 | + margin: new EdgeInsets.only(top: 6.0, bottom: 2.0), |
| 94 | + alignment: Alignment.topLeft), |
| 95 | + new Padding( |
| 96 | + padding: new EdgeInsets.only(left: 0.0, top: 2.0, right: 0.0, bottom: 0.0), |
| 97 | + ), |
| 98 | + bottomContainer, |
| 99 | + ], |
| 100 | + ), |
| 101 | + ), |
| 102 | + ]), |
| 103 | + ), |
| 104 | + ), |
| 105 | + ); |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +class IssueItemViewModel { |
| 110 | + String actionTime = "---"; |
| 111 | + String actionUser = "---"; |
| 112 | + String actionUserPic = "---"; |
| 113 | + String issueComment = "---"; |
| 114 | + String commentCount = "---"; |
| 115 | + String state = "---"; |
| 116 | + String issueTag = "---"; |
| 117 | + |
| 118 | + IssueItemViewModel(); |
| 119 | + |
| 120 | + IssueItemViewModel.fromMap(issueMap) { |
| 121 | + String fullName = CommonUtils.getFullName(issueMap["repository_url"]); |
| 122 | + actionTime = CommonUtils.getNewsTimeStr(DateTime.parse(issueMap["created_at"])); |
| 123 | + actionUser = issueMap["user"]["login"]; |
| 124 | + actionUserPic = issueMap["user"]["avatar_url"]; |
| 125 | + issueComment = fullName + "- " + issueMap["title"]; |
| 126 | + commentCount = issueMap["comments"].toString(); |
| 127 | + state = issueMap["state"]; |
| 128 | + issueTag = "#" + issueMap["number"].toString(); |
| 129 | + } |
| 130 | +} |
0 commit comments