Competition.dart 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import '../model/CompetitionInfo.dart';
  4. import 'package:intl/intl.dart';
  5. import '../pages/RoomList.dart';
  6. import '../pages/CompetitionRooms.dart';
  7. import 'package:gradient_text/gradient_text.dart';
  8. class Competition extends StatelessWidget {
  9. final CompetitionInfo competitionInfo;
  10. Competition(this.competitionInfo);
  11. final Shader linearGradient = LinearGradient(
  12. begin: Alignment.topCenter,
  13. end: Alignment.bottomCenter,
  14. colors: <Color>[Color(0xFFFFC84B), Color(0xFFA26A23)],
  15. ).createShader(Rect.fromLTWH(0.0, 0.0, 200, 70));
  16. @override
  17. Widget build(BuildContext context) {
  18. return GestureDetector(
  19. child: Container(
  20. color: Color(0xFF293354),
  21. height: 80,
  22. margin: EdgeInsets.fromLTRB(15, 7, 15, 7),
  23. child: Stack(
  24. overflow: Overflow.visible,
  25. children: <Widget>[
  26. Center(
  27. child: Row(
  28. children: <Widget>[
  29. Container(
  30. margin: EdgeInsets.only(left: 8),
  31. child: Image.asset(
  32. 'images/game.png',
  33. width: 64,
  34. height: 64,
  35. ),
  36. ),
  37. Expanded(
  38. child: Container(
  39. margin: EdgeInsets.only(left: 10),
  40. height: 64,
  41. child: Column(
  42. crossAxisAlignment: CrossAxisAlignment.start,
  43. children: <Widget>[
  44. Text(
  45. competitionInfo.competitionName,
  46. style: TextStyle(fontSize: 14, color: Colors.white),
  47. ),
  48. Expanded(
  49. child: GradientText(
  50. '¥' + competitionInfo.bonus.toString().replaceAllMapped(RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]},'),
  51. gradient: LinearGradient(
  52. colors: [Color(0xFFFFC84B), Color(0xFFA26A23)],
  53. begin: Alignment.topCenter,
  54. end: Alignment.bottomCenter,
  55. ),
  56. style: TextStyle(fontSize: 20),
  57. textAlign: TextAlign.center),
  58. ),
  59. Text(
  60. '比赛时间' +
  61. DateFormat('yyyy.MM.dd').format(DateTime.fromMicrosecondsSinceEpoch(competitionInfo.startTime * 1000)) +
  62. '-' +
  63. DateFormat('yyyy.MM.dd').format(DateTime.fromMicrosecondsSinceEpoch(competitionInfo.endTime * 1000)),
  64. style: TextStyle(
  65. color: Color(0xFF9A9CA2),
  66. fontSize: 11,
  67. ),
  68. )
  69. ],
  70. ),
  71. ),
  72. )
  73. ],
  74. ),
  75. ),
  76. Positioned(
  77. right: 0,
  78. top: 0,
  79. bottom: 0,
  80. child: Image.asset('images/icon_jinru.png'),
  81. ),
  82. Positioned(
  83. right: 0,
  84. top: 0,
  85. bottom: 0,
  86. child: Container(
  87. width: 50,
  88. height: 80,
  89. child: Center(
  90. child: Text(
  91. '进入',
  92. style: TextStyle(fontSize: 15, color: Colors.white),
  93. ),
  94. ),
  95. ),
  96. ),
  97. Positioned(
  98. right: 60,
  99. top: -2,
  100. width: 52,
  101. height: 35,
  102. child: Container(
  103. transform: Matrix4.translationValues(0.0, -2.0, 0.0),
  104. child: Builder(
  105. builder: (context) {
  106. var src = 'images/icon_paimingno.png';
  107. if (competitionInfo.participatingInfo != null && competitionInfo.participatingInfo.rank > 0) {
  108. if (competitionInfo.participatingInfo.rank == 1) {
  109. src = 'images/icon_paiming01.png';
  110. } else if (competitionInfo.participatingInfo.rank == 2) {
  111. src = 'images/icon_paiming02.png';
  112. } else if (competitionInfo.participatingInfo.rank == 3) {
  113. src = 'images/icon_paiming03.png';
  114. } else {
  115. return Stack(
  116. children: <Widget>[
  117. Image.asset('images/icon_paiming0000.png'),
  118. Align(
  119. alignment: Alignment.topCenter,
  120. child: Container(
  121. margin: EdgeInsets.only(top: 10),
  122. child: Text(
  123. competitionInfo.participatingInfo.rank.toString(),
  124. style: TextStyle(
  125. fontSize: 16,
  126. fontWeight: FontWeight.bold,
  127. color: Colors.white,
  128. ),
  129. ),
  130. ),
  131. ),
  132. ],
  133. );
  134. }
  135. }
  136. return Image.asset(src);
  137. },
  138. ),
  139. ),
  140. ),
  141. Align(
  142. alignment: Alignment.topLeft,
  143. child: Opacity(
  144. opacity: competitionInfo.type == 2 ? 1.0 : 0,
  145. child: Image.asset(
  146. 'images/home_icon_vip.png',
  147. width: 28,
  148. height: 24,
  149. ),
  150. ),
  151. )
  152. ],
  153. ),
  154. ),
  155. onTap: () {
  156. Navigator.push(context, CupertinoPageRoute(builder: (context) => CompetitionRooms(competitionInfo)));
  157. },
  158. );
  159. }
  160. }