Merge branch 'opt-videoPlayerControl' into design

This commit is contained in:
guozhigq
2024-11-26 23:31:45 +08:00
8 changed files with 105 additions and 150 deletions

View File

@ -6,6 +6,7 @@ import 'dart:typed_data';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_volume_controller/flutter_volume_controller.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
@ -113,12 +114,13 @@ class PlPlayerController {
// final Durations durations;
List<Map<String, dynamic>> videoFitType = [
{'attr': BoxFit.contain, 'desc': '包含'},
{'attr': BoxFit.cover, 'desc': '覆盖'},
{'attr': BoxFit.fill, 'desc': ''},
{'attr': BoxFit.fitHeight, 'desc': '度适应'},
{'attr': BoxFit.fitWidth, 'desc': '度适应'},
{'attr': BoxFit.scaleDown, 'desc': '小适应'},
{'attr': BoxFit.contain, 'desc': '自动'},
{'attr': BoxFit.cover, 'desc': '铺满'},
{'attr': BoxFit.fill, 'desc': ''},
{'attr': BoxFit.fitHeight, 'desc': ''},
{'attr': BoxFit.fitWidth, 'desc': ''},
{'attr': BoxFit.scaleDown, 'desc': ''},
{'attr': BoxFit.none, 'desc': '原始'},
];
PreferredSizeWidget? headerControl;
@ -828,47 +830,53 @@ class PlPlayerController {
}
/// Toggle Change the videofit accordingly
void toggleVideoFit() {
showDialog(
context: Get.context!,
builder: (context) {
return AlertDialog(
title: const Text('画面比例'),
content: StatefulBuilder(builder: (context, StateSetter setState) {
return Wrap(
alignment: WrapAlignment.start,
void toggleVideoFit(String toggleType) {
if (toggleType == 'press') {
final String videoFitDEsc = _videoFitDesc.value;
final int index = videoFitType.indexWhere(
(element) => element['desc'] == videoFitDEsc,
);
final int newIndex = index + 1 >= videoFitType.length ? 0 : index + 1;
_videoFit.value = videoFitType[newIndex]['attr'];
_videoFitDesc.value = videoFitType[newIndex]['desc'];
setVideoFit();
SmartDialog.showToast('画面比例:${videoFitType[newIndex]['desc']}');
} else {
void onPressed(item) {
_videoFit.value = item['attr'];
_videoFitDesc.value = item['desc'];
setVideoFit();
Navigator.of(Get.context!).pop();
}
showDialog(
context: Get.context!,
builder: (context) {
return AlertDialog(
title: const Text('画面比例'),
content: Wrap(
spacing: 8,
runSpacing: 2,
children: [
for (var i in videoFitType) ...[
if (_videoFit.value == i['attr']) ...[
FilledButton(
onPressed: () async {
_videoFit.value = i['attr'];
_videoFitDesc.value = i['desc'];
setVideoFit();
Get.back();
},
onPressed: () => onPressed(i),
child: Text(i['desc']),
),
] else ...[
FilledButton.tonal(
onPressed: () async {
_videoFit.value = i['attr'];
_videoFitDesc.value = i['desc'];
setVideoFit();
Get.back();
},
onPressed: () => onPressed(i),
child: Text(i['desc']),
),
]
]
],
);
}),
);
},
);
),
);
},
);
}
}
/// 缓存fit