Hibok
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

149 рядки
4.7 KiB

  1. import 'dart:convert';
  2. import 'package:chat/data/constants.dart';
  3. import 'package:chat/generated/i18n.dart';
  4. import 'package:chat/models/ChatMsg.dart';
  5. import 'package:chat/proto/chat.pbserver.dart';
  6. import 'package:chat/r.dart';
  7. import 'package:chat/utils/MessageMgr.dart';
  8. import 'package:chat/utils/app_navigator.dart';
  9. import 'package:chat/utils/screen.dart';
  10. import 'package:flutter/material.dart';
  11. class RedBagItem extends StatefulWidget {
  12. final MsgModel msgModel;
  13. final int sendId;
  14. RedBagItem(Key key, this.sendId, this.msgModel) : super(key: key);
  15. @override
  16. _RedBagItemState createState() => _RedBagItemState();
  17. }
  18. class _RedBagItemState extends State<RedBagItem> {
  19. RedWallet wallet;
  20. List<int> translateStr;
  21. @override
  22. void initState() {
  23. super.initState();
  24. wallet = RedWallet.fromBuffer(widget.msgModel.msgContent);
  25. translateStr = widget.msgModel.translateContent;
  26. MessageMgr().on('Update RedWalletState', updateRedWalletState);
  27. }
  28. @override
  29. void dispose() {
  30. MessageMgr().off('Update RedWalletState', updateRedWalletState);
  31. super.dispose();
  32. }
  33. updateRedWalletState(walletInfo) {
  34. if (walletInfo.orderId == wallet.orderId) {
  35. wallet.state = walletInfo.state;
  36. if (mounted) {
  37. setState(() {});
  38. }
  39. }
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. var msg;
  44. var bgColor = Color(0xFFFF9936);
  45. if (wallet.state == RedWalletState.Expire) {
  46. msg = I18n.of(context).over_time;
  47. bgColor = Color(0xFFFF9936).withOpacity(0.5);
  48. } else if (wallet.state == RedWalletState.Received) {
  49. msg = I18n.of(context).has_get;
  50. bgColor = Color(0xFFFF9936).withOpacity(0.5);
  51. }
  52. var titleStr;
  53. if (translateStr != null && translateStr.length > 0) {
  54. print('红包有翻译内容');
  55. titleStr = utf8.decode(translateStr);
  56. } else {
  57. titleStr = wallet.title;
  58. }
  59. print('红包内容:$titleStr');
  60. var title = SizedBox(
  61. width: Screen.width - 220,
  62. child: Text(
  63. titleStr,
  64. textScaleFactor: 1.0,
  65. maxLines: 1,
  66. overflow: TextOverflow.ellipsis,
  67. style: TextStyle(fontSize: 16, color: Colors.white),
  68. ));
  69. var borderRadius;
  70. double radius = 7.5;
  71. borderRadius = BorderRadius.all(Radius.circular(radius));
  72. return GestureDetector(
  73. child: ClipRRect(
  74. borderRadius: borderRadius,
  75. child: Container(
  76. decoration: BoxDecoration(boxShadow: [
  77. BoxShadow(
  78. color: const Color(0x29B3B4B7),
  79. offset: Offset(0, 5),
  80. blurRadius: 5.5),
  81. ]),
  82. constraints: BoxConstraints(maxWidth: Screen.width - 160),
  83. child: Column(
  84. children: <Widget>[
  85. Container(
  86. height: 50,
  87. padding: EdgeInsets.symmetric(vertical: 5, horizontal: 8),
  88. color: bgColor,
  89. child: Row(
  90. mainAxisAlignment: MainAxisAlignment.center,
  91. children: <Widget>[
  92. Container(
  93. padding: EdgeInsets.all(2.5),
  94. decoration: BoxDecoration(
  95. shape: BoxShape.circle,
  96. color: Colors.white.withOpacity(0.22)),
  97. child: Image.asset(R.assetsImagesCoin, scale: 2),
  98. ),
  99. SizedBox(width: 5),
  100. msg != null
  101. ? Column(
  102. mainAxisAlignment: MainAxisAlignment.center,
  103. crossAxisAlignment: CrossAxisAlignment.start,
  104. children: <Widget>[
  105. title,
  106. fixedText(msg,
  107. fontSize: 11, color: Colors.white70)
  108. ],
  109. )
  110. : title
  111. ],
  112. ),
  113. ),
  114. Container(
  115. height: 20,
  116. width: double.infinity,
  117. color: Colors.white,
  118. alignment: Alignment.centerLeft,
  119. padding: EdgeInsets.only(left: 20),
  120. child: fixedText(I18n.of(context).red_money,
  121. fontSize: 10, color: Constants.GreyTextColor),
  122. )
  123. ],
  124. ),
  125. )),
  126. onTap: () {
  127. print('点击红包');
  128. AppNavigator.pushCoinBagInfoPage(context, widget.msgModel, titleStr);
  129. },
  130. );
  131. }
  132. }