AudioCacha包中没有预定义播放方法

问题描述 投票:0回答:0
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:audioplayers/src/audio_cache.dart';


void main() {
  runApp(const xylophonePage());
}

class xylophonePage extends StatefulWidget {
  const xylophonePage({Key? key}) : super(key: key);

  @override
  State<xylophonePage> createState() => _xylophonePageState();
}

class _xylophonePageState extends State<xylophonePage> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Center(
            child: TextButton(onPressed: () {

          ///In the following two lines I got an error when I was trying to use the play method:

              final player = new AudioCacha();
              player.play('explosion.mp3');

            },
                child: Text('Click Me')),
          ),
        ),
      ),
    );
  }
}

应该发生的是当我尝试使用 play 方法时它应该可以正常工作,因为我已将它添加到依赖项部分并且它已在外部库中定义

flutter dart flutter-dependencies flutter-animation
© www.soinside.com 2019 - 2024. All rights reserved.