HouseItem.dart 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:wanna_battle/model/PlayerInfo.dart';
  4. import '../model/HouseInfo.dart';
  5. import '../model/GameInfo.dart';
  6. import '../pages/RoomInfo.dart';
  7. import 'package:cached_network_image/cached_network_image.dart';
  8. import 'dart:ui';
  9. typedef void OnTapHomeMenu();
  10. class HouseItem extends StatelessWidget {
  11. HouseItem(this.houseInfo, this.gameInfo, {this.playerInfo = null, this.isNext = true, this.onTapHomeMenu, this.onBack, this.onNext, this.isHome = false});
  12. HouseInfo houseInfo;
  13. GameInfo gameInfo;
  14. PlayerInfo playerInfo;
  15. bool isNext;
  16. OnTapHomeMenu onTapHomeMenu;
  17. OnTapHomeMenu onBack;
  18. OnTapHomeMenu onNext;
  19. bool isHome;
  20. List<String> imageList = ['images/img_fangjian_hong.png', 'images/img_fangjian_huise.png'];
  21. @override
  22. Widget build(BuildContext context) {
  23. return Container(
  24. margin: EdgeInsets.only(bottom: 10, left: 15, right: 15),
  25. decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(4))),
  26. child: Material(
  27. color: Colors.transparent,
  28. child: InkWell(
  29. onTap: () async {
  30. if (!isNext) {
  31. onTapHomeMenu();
  32. } else {
  33. if (isHome) {
  34. onNext();
  35. }
  36. bool res = await Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomInfo(roomId: houseInfo.id.toString())));
  37. if (res != null && res) {
  38. if (isHome) {
  39. onBack();
  40. }
  41. }
  42. }
  43. //
  44. },
  45. child: Container(
  46. height: 80,
  47. decoration: BoxDecoration(
  48. image: DecorationImage(
  49. image: AssetImage(imageList[houseInfo.statusFlag == 0 ? 0 : 1]), fit: BoxFit.fitHeight, alignment: Alignment.bottomRight),
  50. ),
  51. padding: EdgeInsets.all(10),
  52. child: Row(
  53. children: <Widget>[
  54. ClipRRect(
  55. borderRadius: BorderRadius.circular(4.0),
  56. child: CachedNetworkImage(
  57. imageUrl: gameInfo.icon,
  58. width: 60,
  59. height: 60,
  60. fit: BoxFit.cover,
  61. ),
  62. ),
  63. Container(
  64. width: 10,
  65. ),
  66. Expanded(
  67. flex: 1,
  68. child: Column(
  69. mainAxisAlignment: MainAxisAlignment.center,
  70. crossAxisAlignment: CrossAxisAlignment.start,
  71. children: <Widget>[
  72. Text(houseInfo.houseName, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 16, color: Colors.black)),
  73. Container(
  74. height: 4,
  75. ),
  76. Text('目标:杀戮${houseInfo.killnumber}人', style: TextStyle(fontSize: 13, color: Color(0xFF999999)))
  77. ],
  78. ),
  79. ),
  80. Column(
  81. mainAxisAlignment: MainAxisAlignment.center,
  82. children: <Widget>[
  83. _topWidget(playerInfo),
  84. Row(
  85. children: <Widget>[
  86. Image.asset('images/house1.png'),
  87. Text(
  88. '${houseInfo.playerNumber != null ? houseInfo.playerNumber : 0}/${houseInfo.maxNumber}',
  89. style: TextStyle(color: Colors.white, fontSize: 14),
  90. )
  91. ],
  92. )
  93. ],
  94. )
  95. ],
  96. ),
  97. ))));
  98. }
  99. Widget _topWidget(PlayerInfo playerInfo) {
  100. if (playerInfo == null) {
  101. if (houseInfo.statusFlag == 0) {
  102. return Image.asset('images/join.png');
  103. } else if (houseInfo.statusFlag == 2) {
  104. return Text('进行中', style: TextStyle(color: Color(0xFF5C5C5C), fontSize: 14, fontWeight: FontWeight.w600));
  105. } else if (houseInfo.statusFlag == 3) {
  106. return Text('解析中', style: TextStyle(color: Color(0xFF5C5C5C), fontSize: 14, fontWeight: FontWeight.w600));
  107. } else if (houseInfo.statusFlag == 8) {
  108. return Text('结算中', style: TextStyle(color: Color(0xFF5C5C5C), fontSize: 14, fontWeight: FontWeight.w600));
  109. } else {
  110. return Text('已结束', style: TextStyle(color: Color(0xFF5C5C5C), fontSize: 14, fontWeight: FontWeight.w600));
  111. }
  112. } else {
  113. if (houseInfo.statusFlag == 2 || houseInfo.statusFlag == 3) {
  114. return Text('待结算', style: TextStyle(color: Color(0xFF5C5C5C), fontSize: 14, fontWeight: FontWeight.w600));
  115. } else if (houseInfo.statusFlag == 8) {
  116. return Text('结算中', style: TextStyle(color: Color(0xFF5C5C5C), fontSize: 14, fontWeight: FontWeight.w600));
  117. } else if (playerInfo.houseRank != null &&
  118. playerInfo.statusFlag != 7 &&
  119. playerInfo.statusFlag != 9 &&
  120. !playerInfo.dataError &&
  121. playerInfo.statusFlag != 6 &&
  122. playerInfo.killNumber >= playerInfo.needkill) {
  123. if (playerInfo.houseRank < 4) {
  124. return Text('第${playerInfo.houseRank}名', style: TextStyle(color: Color(0xFFD4504B), fontSize: 14, fontWeight: FontWeight.w600));
  125. } else {
  126. return Text('第${playerInfo.houseRank}名', style: TextStyle(color: Color(0xFF5C5C5C), fontSize: 14, fontWeight: FontWeight.w600));
  127. }
  128. } else {
  129. return Text('任务失败', style: TextStyle(color: Color(0xFF5C5C5C), fontSize: 14, fontWeight: FontWeight.w600));
  130. }
  131. }
  132. // return Container();
  133. }
  134. }