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 方法时它应该可以正常工作,因为我已将它添加到依赖项部分并且它已在外部库中定义