import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:trackoffical_app/model/m_control_point.dart'; import 'package:trackoffical_app/service/game/game_model.dart'; import 'package:trackoffical_app/utils.dart'; import 'package:trackoffical_app/view/ingame/in_game_controller.dart'; import 'package:screen_brightness/screen_brightness.dart'; import '../../service/game/game.dart'; import '../../widget/app_dialog.dart'; import 'checked_cp_record.dart'; extension MCPExt on MControlPoint{ Widget display({TextStyle? textStyle, double? height}){ final next = this; if (next.sn == MControlPoint.snStart || next.sn == MControlPoint.snFinish) { var src = 'ic_bottom_bar_next_start.png'; if (next.sn == MControlPoint.snFinish) { src = 'ic_bottom_bar_next_finish.png'; } return Image.asset( 'assets/images/$src', height: height??22, fit: BoxFit.fitHeight, color: Colors.white, ); } return Text(next.sn, style: textStyle); } Widget icon({double? height}){ final next = this; var src = 'ic_cp.png'; if(next.isStart){ src = 'ic_cp_start.png'; } if(next.isFinish){ src = 'ic_cp_finish.png'; } return Image.asset( 'assets/images/$src', height: height??22, fit: BoxFit.fitHeight, ); } } extension MCPNullableExt on MControlPoint?{ Widget display({TextStyle? textStyle, double? height}){ Widget text; final nextCp = this; if (nextCp != null) { text = nextCp.display(textStyle: textStyle); if (nextCp.areaId.isNotEmpty && nextCp.type == MControlPointType.nfc) { text = Row( mainAxisSize: MainAxisSize.min, children: [ text, Text( ' (${nextCp.areaId})', style: textStyle, ) ], ); } } else { text = Text('--', style: textStyle, maxLines: 1); } return text; } } class _TwoValueElem extends StatelessWidget{ const _TwoValueElem({ required this.value1, required this.value2, required this.unit, required this.fontSize }); final String value1; final String value2; final String unit; final double fontSize; @override Widget build(BuildContext context) { final small = fontSize * 0.875; final unitSize = small -2; return Row( children: [ Expanded(child: Column( mainAxisSize: MainAxisSize.min, children: [ SizedBox( width: context.width, child: Text(value1, maxLines: 1, style: TextStyle(fontSize: small))), Container(height: 1, width: context.width, color: Colors.white,), SizedBox( width: context.width, child: Text(value2, maxLines: 1, textAlign: TextAlign.end, style: TextStyle(fontSize: fontSize))), ], )), const SizedBox(width: 5), Text(unit, style: TextStyle(fontSize: unitSize)) ], ); } } extension GameModelExt on GameModel{ Widget widgetDistance({double fontSize = 17.4, bool withTrip = true}) { final small = fontSize * 0.875; final unitSize = small -2; if (withTrip){ return _TwoValueElem( value1: (myPositionHistoryLenFromLastCP.m).round().toString(), value2: (myPositionHistoryLen.value.m).round().toString(), unit: 'm', fontSize: fontSize); }else{ var (value, unit) = myPositionHistoryLen.value.toStringValueAndUnit(); return RichText(text: TextSpan( text: value, style: TextStyle(fontSize: fontSize), children: [ TextSpan(text: unit, style: TextStyle(fontSize: unitSize)) ] )); } } String paceString(Duration pace){ if(pace.inMinutes> 99){ return '99+\''; } return pace.toMinSecondString(); } Widget widgetPace({double fontSize = 17.4, bool withTrip = true}) { final small = fontSize * 0.875; final unitSize = small -2; if (withTrip){ return _TwoValueElem( value1: paceString(paceSecondKmFromLastCP.value), value2: paceString(paceSecondKm.value), unit: '/km', fontSize: fontSize); }else{ return RichText(text: TextSpan( text: paceString(paceSecondKm.value), style: TextStyle(fontSize: fontSize), children: [ TextSpan(text: '/km', style: TextStyle(fontSize: unitSize)) ] )); } } } Widget wSport(String value, String iconSrc, {TextStyle? textStyle}) { return Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text(value, maxLines: 1, overflow: TextOverflow.clip, style: textStyle), Image.asset(iconSrc, height: 14.16)], ); } void showCheckedPoints(List data) { final textStyle = Get.theme.textTheme.titleLarge; Get.dialog( Card( color: Colors.white, surfaceTintColor: Colors.white, margin: const EdgeInsets.fromLTRB(40, 50, 40, 100), child: Padding( padding: const EdgeInsets.all(20), child: Column( children: [ Text('打点记录', style: textStyle), const SizedBox(height: 12), Expanded( child: CheckedCPRecord( data: data, ), ), // SizedBox( // child: CheckPointRecord(data: controller.checkedPointHistory), // ), FilledButton( onPressed: () => Get.back(), child: const Text('确定')) ], ), )), ); } Widget getSmallTitle(String title){ return Container( alignment: Alignment.center, padding: const EdgeInsets.only(left: 3, right: 3), decoration: const BoxDecoration(color: Colors.black), child: Text(title, style: const TextStyle( fontSize:11, color: Colors.white, fontWeight: FontWeight.w700)) ); } Future get isBrightnessMax async{ final b = await ScreenBrightness().current; return b>=1; } void onButtonExit(InGameController controller) { Get.dialog(AppDialog( title: const Text('退出比赛'), content: const Text('是否强制结束?'), onConfirm: () async { controller.forceExit(); }, onCancel: () => Get.back(), onConfirmText: '是', onCancelText: '否', )); }