| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import 'dart:io';
- import 'package:electronic_assistant/base/base_controller.dart';
- import 'package:electronic_assistant/handler/audio_picker_handler.dart';
- import 'package:electronic_assistant/utils/toast_util.dart';
- import 'package:get/get.dart';
- import 'package:photo_manager/photo_manager.dart';
- import 'package:uuid/uuid.dart';
- import '../../data/bean/talks.dart';
- import '../../data/repositories/talk_repository.dart';
- import '../talk/view.dart';
- class AudioPickerController extends BaseController {
- final audioList = RxList<AssetEntity>();
- AssetPathEntity? currentPath;
- @override
- void onReady() async {
- super.onReady();
- if (!await AudioPickerHandler.hasPermission()) {
- bool permission = await AudioPickerHandler.requestPermissionExtend();
- if (!permission) {
- ToastUtil.showToast('授权失败');
- return;
- }
- }
- currentPath = await initPathEntity();
- requestList();
- }
- void requestList() {
- if (currentPath == null) {
- return;
- }
- AudioPickerHandler.getAssetList(currentPath!, 0).then((value) {
- audioList.addAll(value);
- });
- }
- Future<AssetPathEntity?> initPathEntity() async {
- List<AssetPathEntity> listEntity =
- await AudioPickerHandler.getAssetPathList();
- if (listEntity.isEmpty) {
- return null;
- }
- return listEntity.first;
- }
- void onItemClick(AssetEntity entity) async {
- File? file = await entity.file;
- if (file == null) {
- ToastUtil.showToast('文件不存在');
- return;
- }
- //上传文件
- TalkBean bean = await talkRepository.talkCreate(
- const Uuid().v4(), entity.duration,
- localAudioUrl: entity.id, uploadType: 1);
- Get.back();
- TalkPage.start(bean);
- }
- }
|