layer_warn.dart 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:trackoffical_app/screen.dart';
  4. import '../../service/game/game_model.dart';
  5. import 'in_game_controller.dart';
  6. import 'package:trackoffical_app/appcore/ffi.dart' as ffi;
  7. class LayerWarn extends GetView<InGameController> {
  8. const LayerWarn({super.key});
  9. @override
  10. Widget build(BuildContext context) {
  11. final model = Get.find<GameModel>();
  12. return Obx(() {
  13. String? warnTitle;
  14. String? warnContent;
  15. Color background = Colors.transparent;
  16. final mask = Colors.white.withAlpha((255 * 0.7).toInt());
  17. if (controller.isShowPhoneHorizontalWarn) {
  18. warnContent = '请水平放置手机\n以获取准确方向';
  19. }
  20. final zone = model.zone.value;
  21. if (zone != null) {
  22. background = mask;
  23. }
  24. switch (zone) {
  25. case ffi.ZoneType.Road:
  26. warnTitle = '道路';
  27. warnContent = '您在穿越车行道路,请抬头注意安全!';
  28. break;
  29. case ffi.ZoneType.River:
  30. warnTitle = '靠近河流';
  31. warnContent = '您正在靠近河流,请抬头注意安全!';
  32. break;
  33. case ffi.ZoneType.Lake:
  34. warnTitle = '靠近湖泊';
  35. warnContent = '您正在靠近湖泊,请抬头注意安全!';
  36. break;
  37. case ffi.ZoneType.ParkingLot:
  38. warnTitle = '停车场';
  39. warnContent = '您在停车场区域,请抬头注意安全!';
  40. break;
  41. case ffi.ZoneType.ForbiddenZone:
  42. warnTitle = '禁区';
  43. warnContent = '您正在穿行禁区,请尽快离开!';
  44. break;
  45. case ffi.ZoneType.Lawn:
  46. warnTitle = '草坪';
  47. warnContent = '请勿踩踏草坪,请尽快离开!';
  48. break;
  49. default:
  50. break;
  51. }
  52. if (controller.isShowOutBoundaryWarn) {
  53. warnTitle = '您已离开场地';
  54. warnContent = '请返回';
  55. background = mask;
  56. }
  57. final style = TextStyle(color: Colors.red, fontSize: 6.11.wp);
  58. return warnContent != null
  59. ? Container(
  60. width: double.infinity,
  61. height: double.infinity,
  62. color: background,
  63. alignment: Alignment.topCenter,
  64. child:
  65. Container(
  66. width: 40.0.wp ,
  67. margin: EdgeInsets.only(top: 30.0.wp),
  68. padding: const EdgeInsets.all(6),
  69. decoration: BoxDecoration(
  70. border: Border.all(color: const Color(0xffff870d)),
  71. color: Colors.orangeAccent.withAlpha(80),
  72. borderRadius: BorderRadius.circular(7)),
  73. child: Column(
  74. mainAxisSize: MainAxisSize.min,
  75. children: [
  76. warnTitle != null
  77. ? Text(warnTitle, style: style)
  78. : const SizedBox(),
  79. Text(
  80. warnContent,
  81. style: style.copyWith(fontSize: 4.58.wp),
  82. ),
  83. ],
  84. ))
  85. )
  86. : const Positioned(child: SizedBox());
  87. });
  88. }
  89. }