| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- 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<MControlPoint> 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<bool> 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: '否',
- ));
- }
|