dialog_finish_result.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import 'package:assets_audio_player/assets_audio_player.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:trackoffical_app/generated/assets.dart';
  5. import 'package:trackoffical_app/route.dart';
  6. import 'package:trackoffical_app/screen.dart';
  7. import 'package:trackoffical_app/utils.dart';
  8. import 'package:trackoffical_app/view/ingame/dialog/dialog_base.dart';
  9. import 'package:trackoffical_app/pb.dart' as pb;
  10. import '../../../styles/theme.dart';
  11. import 'dialog_button.dart';
  12. Widget _elem(String iconSrc, String title, String value, String unit) {
  13. final style = TextStyle(
  14. fontSize: 45.8.rpx,
  15. fontWeight: FontWeight.w500,
  16. color: const Color(0xff333333));
  17. return Padding(
  18. padding: EdgeInsets.only(top: 21.0.rpx, bottom: 21.0.rpx),
  19. child: Row(
  20. children: [
  21. Image.asset(iconSrc, height: 45.8.rpx),
  22. SizedBox(width: 9.5.rpx),
  23. Expanded(
  24. child: Text(
  25. title,
  26. style: style.copyWith(fontSize: 34.35.rpx),
  27. )),
  28. RichText(
  29. text: TextSpan(text: value, style: style, children: [
  30. TextSpan(
  31. text: unit,
  32. style: style.copyWith(
  33. fontSize: 19.1.rpx, color: const Color(0xff818181)),
  34. ),
  35. ]))
  36. ],
  37. ));
  38. }
  39. void _goNext(){
  40. Get.offAllNamed(RouteName.home);
  41. }
  42. enum _State{
  43. success,
  44. ok,
  45. fail
  46. }
  47. void dialogFinishResult(pb.GameSettlement data) {
  48. var state = _State.success;
  49. var title = '恭喜!挑战成功';
  50. var titleColor = const Color(0xFFFF870D);
  51. Color? buttonColor = const Color(0xFF017DC7);
  52. var soundSrc = Assets.soundFinishSuccess;
  53. if(!data.isSuccess){
  54. state = _State.ok;
  55. }
  56. if(!data.isComplete){
  57. state=_State.fail;
  58. }
  59. switch(state){
  60. case _State.ok:
  61. title = '挑战完成';
  62. titleColor = Colors.red;
  63. buttonColor = null;
  64. soundSrc = Assets.soundFinishOk;
  65. break;
  66. case _State.fail:
  67. title = '挑战失败';
  68. titleColor = Colors.red;
  69. buttonColor = null;
  70. soundSrc = Assets.soundFinishFail;
  71. break;
  72. default:
  73. }
  74. AssetsAudioPlayer.newPlayer().open(
  75. Audio(soundSrc),
  76. autoStart: true,
  77. showNotification: false);
  78. final minutes = data.duration.toDuration().inSeconds.toDouble() /
  79. Duration.secondsPerMinute;
  80. final distanceKm = data.distance.toDouble() / 1000;
  81. final kcal = data.calorie.toDouble() / 1000;
  82. Get.dialog(
  83. WillPopScope(
  84. onWillPop: () async{
  85. _goNext();
  86. return false;
  87. },
  88. child: dialogTitle(
  89. title,
  90. titleColor,
  91. Column(
  92. crossAxisAlignment: CrossAxisAlignment.center,
  93. children: [
  94. Card(
  95. child: Padding(
  96. padding: EdgeInsets.fromLTRB(
  97. 41.1.rpx,
  98. 10.1.rpx,
  99. 41.1.rpx,
  100. 10.1.rpx,
  101. ),
  102. child: Column(
  103. children: [
  104. _elem(Assets.imagesIcFinishTime, '总用时',
  105. minutes.toStringAsFixed(1), ' min '),
  106. _elem(Assets.imagesIcFinishTime, '总里程',
  107. distanceKm.toStringAsFixed(1), ' km '),
  108. _elem(Assets.imagesIcFinishTime, '消耗卡路里',
  109. kcal.toStringAsFixed(1), ' kcal'),
  110. _elem(Assets.imagesIcFinishTime, '脑力值',
  111. data.answerHistory.accuracy.toString(), ' % '),
  112. ],
  113. )),
  114. ),
  115. SizedBox(height: 30.0.rpx),
  116. Row(
  117. mainAxisSize: MainAxisSize.min,
  118. children: [
  119. Image.asset(Assets.imagesIcBean, height: 103.9.rpx),
  120. Column(
  121. mainAxisSize: MainAxisSize.min,
  122. children: [
  123. Text('X ${data.sysPoint}',
  124. style: TextStyle(fontSize: 53.44.rpx)),
  125. Text('共获得${data.sysPoint}个百味豆',
  126. style: TextStyle(
  127. fontSize: 22.9.rpx,
  128. color: const Color(0xFFaaaaaa))),
  129. ],
  130. )
  131. ],
  132. ),
  133. SizedBox(height: 30.0.rpx),
  134. dialogButton('确定', _goNext, color: buttonColor),
  135. SizedBox(height: 30.0.rpx),
  136. Text(
  137. '提示:可以在“成就”中查看详细数据',
  138. style: TextStyle(color: Colors.red, fontSize: 28.63.rpx),
  139. )
  140. ],
  141. )),),
  142. barrierDismissible: false
  143. );
  144. }
  145. class _Empty extends StatelessWidget {
  146. @override
  147. Widget build(BuildContext context) {
  148. SizeFit.screenInit(context);
  149. final data = pb.GameSettlement();
  150. return Scaffold(
  151. floatingActionButton: FloatingActionButton(onPressed: () {
  152. dialogFinishResult(data);
  153. }),
  154. );
  155. }
  156. }
  157. void main() async {
  158. runApp(GetMaterialApp(theme: appThemeData(), home: _Empty()));
  159. }