基础库
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

235 rindas
7.5 KiB

  1. import 'dart:math';
  2. import 'package:flutter/material.dart';
  3. import 'package:loading_indicator/loading_indicator.dart';
  4. import 'package:zhiying_comm/zhiying_comm.dart';
  5. import 'turn_chain_style_model.dart';
  6. class TurnChainLoading {
  7. static OverlayEntry _overlayEntry;
  8. static Future show(
  9. BuildContext context,
  10. TurnChainStyleModel model,
  11. ) async {
  12. dismiss();
  13. _overlayEntry = new OverlayEntry(builder: (context) {
  14. return GestureDetector(
  15. onTap: dismiss,
  16. child: Container(
  17. color: Colors.black.withOpacity(0.3),
  18. child: TurnChainDialogWidget(model),
  19. ),
  20. );
  21. });
  22. try {
  23. //插入到 Overlay中显示 OverlayEntry
  24. Overlay.of(context).insert(_overlayEntry);
  25. } catch (e, s) {
  26. Logger.error(e, s);
  27. }
  28. }
  29. static dismiss() {
  30. try {
  31. _overlayEntry?.remove();
  32. _overlayEntry = null;
  33. } catch (e, s) {
  34. Logger.error(e, s);
  35. }
  36. }
  37. }
  38. class TurnChainDialogWidget extends StatelessWidget {
  39. TurnChainStyleModel model;
  40. TurnChainDialogWidget(this.model);
  41. @override
  42. Widget build(BuildContext context) {
  43. return WillPopScope(
  44. onWillPop: () {
  45. return Future.value(false);
  46. },
  47. child: Scaffold(
  48. backgroundColor: HexColor.fromHex('#54555555'),
  49. body: Center(
  50. child: Container(
  51. height: 250,
  52. width: 260,
  53. // margin: const EdgeInsets.symmetric(horizontal: 70),
  54. padding: const EdgeInsets.all(20),
  55. decoration: BoxDecoration(
  56. color: HexColor.fromHex('#FEFFFE'),
  57. borderRadius: BorderRadius.circular(13),
  58. ),
  59. child: Column(
  60. mainAxisAlignment: MainAxisAlignment.center,
  61. crossAxisAlignment: CrossAxisAlignment.center,
  62. children: <Widget>[
  63. /// 跳转图标
  64. _buildTransitionIconWidget(),
  65. /// 正在跳转提示文字
  66. Padding(padding: const EdgeInsets.only(top: 12), child: _buildJumpTipWidget()),
  67. /// 返利和券
  68. Padding(padding: const EdgeInsets.only(top: 13), child: _buildCouponAndRebateWidget()),
  69. // /// 共省提示
  70. Padding(padding: const EdgeInsets.only(top: 14), child: _buildSaveMoneyTipWidget()),
  71. /// 注意提示文字
  72. Padding(padding: const EdgeInsets.only(top: 8, left: 9.5, right: 9.5), child: _buildNoticeWidget()),
  73. ],
  74. )),
  75. ),
  76. ),
  77. );
  78. }
  79. /// 过渡图标
  80. Widget _buildTransitionIconWidget() {
  81. return Container(
  82. height: 50,
  83. child: Row(
  84. crossAxisAlignment: CrossAxisAlignment.center,
  85. mainAxisAlignment: MainAxisAlignment.center,
  86. children: <Widget>[
  87. Container(
  88. margin: const EdgeInsets.only(right: 8),
  89. width: 50,
  90. height: 50,
  91. child: CachedNetworkImage(
  92. imageUrl: model?.appLogo ?? '',
  93. ),
  94. ),
  95. Container(
  96. height: 10,
  97. width: 34,
  98. child: LoadingIndicator(
  99. indicatorType: Indicator.ballPulse,
  100. color: HexColor.fromHex('#FE7978'),
  101. colors: [
  102. HexColor.fromHex('#FF2020'),
  103. HexColor.fromHex('#FE7978'),
  104. HexColor.fromHex('#FEBCBB'),
  105. ],
  106. ),
  107. ),
  108. Container(
  109. margin: const EdgeInsets.only(left: 8),
  110. width: 50,
  111. height: 50,
  112. // color: Colors.red,
  113. child: CachedNetworkImage(
  114. imageUrl: _getProviderIcon(),
  115. ),
  116. ),
  117. ],
  118. ),
  119. );
  120. }
  121. String _getProviderIcon() {
  122. int length = model?.style?.providerIcons?.length ?? 0;
  123. String result = '';
  124. if (length > 0) {
  125. model.style.providerIcons.forEach((element) {
  126. if (element.type == model.provider) {
  127. result = element?.img ?? '';
  128. }
  129. });
  130. }
  131. return result;
  132. }
  133. /// 跳转文字提示
  134. Widget _buildJumpTipWidget() {
  135. return Text(
  136. '${model?.style?.text}${model.providerName}',
  137. style: TextStyle(color: HexColor.fromHex('#333333'), fontSize: 15, fontWeight: FontWeight.bold),
  138. );
  139. }
  140. /// 返利与优惠券
  141. Widget _buildCouponAndRebateWidget() {
  142. return Container(
  143. height: 30,
  144. child: Row(
  145. mainAxisAlignment: MainAxisAlignment.center,
  146. children: <Widget>[
  147. _buildCustomButtonWidget(
  148. text: model?.style?.leftBtnText ?? '返利',
  149. textColor: model?.style?.leftBtnTextColor ?? '#FEFFFE',
  150. number: !EmptyUtil.isEmpty(model?.commission) ? model?.commission : '0.00',
  151. numberColor: model?.style?.leftBtnTextColor ?? '#FEFFFE',
  152. bgColor: model?.style?.leftBtnColor ?? '#FF2020',
  153. bgImg: model?.style?.leftBtnImg ?? ''),
  154. const SizedBox(width: 8),
  155. _buildCustomButtonWidget(
  156. text: model?.style?.rightBtnText ?? '券',
  157. textColor: model?.style?.rightBtnTextColor ?? '#FEFFFE',
  158. number: !EmptyUtil.isEmpty(model?.coupon) ? model?.coupon : '0.00',
  159. numberColor: model?.style?.rightBtnTextColor ?? '#FEFFFE',
  160. bgColor: model?.style?.rightBtnColor ?? '#FF2020',
  161. bgImg: model?.style?.rightBtnImg ?? ''),
  162. ],
  163. ),
  164. );
  165. }
  166. Widget _buildCustomButtonWidget({String text, String textColor, String number, String numberColor, String bgColor, String bgImg}) {
  167. return Container(
  168. height: 30,
  169. width: 95,
  170. alignment: Alignment.center,
  171. decoration: BoxDecoration(
  172. borderRadius: BorderRadius.circular(8),
  173. color: !EmptyUtil.isEmpty(bgImg) ? null : HexColor.fromHex(bgColor),
  174. image: EmptyUtil.isEmpty(bgImg)
  175. ? null
  176. : DecorationImage(
  177. image: CachedNetworkImageProvider(bgImg ?? ''),
  178. )),
  179. child: RichText(
  180. text: TextSpan(children: [
  181. TextSpan(
  182. text: text ?? '',
  183. style: TextStyle(color: HexColor.fromHex(textColor), fontSize: 13),
  184. ),
  185. TextSpan(
  186. text: number ?? '',
  187. style: TextStyle(color: HexColor.fromHex(numberColor), fontFamily: 'Din', package: 'zhiying_comm', fontSize: 13),
  188. ),
  189. ]),
  190. ));
  191. }
  192. /// 总共省下多少钱的提示
  193. Widget _buildSaveMoneyTipWidget() {
  194. return RichText(
  195. text: TextSpan(children: [
  196. TextSpan(text: model?.style?.saveMomenyText ?? '共省 ¥', style: TextStyle(color: HexColor.fromHex(model?.style?.saveMomenyColor ?? '#FF2020'), fontSize: 13)),
  197. TextSpan(
  198. text: model?.totalSave ?? '0.00',
  199. style: TextStyle(color: HexColor.fromHex(model?.style?.saveMomenyColor ?? '#FF2020'), fontSize: 18, fontFamily: 'Din', package: 'zhiying_comm')),
  200. // TextSpan(text: '.99', style: TextStyle(color: HexColor.fromHex(model?.style?.saveMomenyColor ?? '#FF2020'), fontSize: 13, fontFamily: 'Din', package: 'zhiying_comm')),
  201. ]),
  202. );
  203. }
  204. /// 注意提示文字提示
  205. Widget _buildNoticeWidget() {
  206. return Text(
  207. model?.style?.tipText ?? '注意:使用红包下单,会导致收益变少,或没有收益!',
  208. textAlign: TextAlign.center,
  209. maxLines: 2,
  210. overflow: TextOverflow.ellipsis,
  211. style: TextStyle(color: HexColor.fromHex(model?.style?.tipColor ?? '#999999'), fontSize: 11),
  212. );
  213. }
  214. }