in my flutter application I want to make a audio player here is my code but the problem is that when I click in icon button nothing happen and the audio don't start how can I fix this
import 'dart:async';
import 'dart:ui';
import 'package: flutter/cupertino.dart';
import 'package: flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:google_fonts/google_fonts.dart';
class CalmForest extends StatefulWidget {
const CalmForest({super.key});
@override
State<CalmForest> createState() => _CalmForestState();
}
class _CalmForestState extends State<CalmForest> {
//const CalmForest({super.key});
final AudioPlayer player = AudioPlayer();
void playAudio() async {
final audioPlayer = AudioPlayer();
final audioSource = AssetSource('assets/audio/Forest.mp3');
await audioPlayer.play(audioSource);
}
the audio is from assets
I am using audioplayers: ^6.0.0 for playing audio
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/forest.png'),
fit: BoxFit.cover,
),
),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 8, sigmaY: 8),
child: ClipRect(
child: Container(
color: Colors.black.withOpacity(0.5),
child: Stack(
children: [
Center(
child: Container(
width: 250,
height: 300,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/forest.png'))),
),
),
SizedBox(
height: 10,
),
Align(
alignment: Alignment.bottomCenter,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 10,
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.graphic_eq,
size: 30, color: Colors.white),
SizedBox(
width: 25,
),
Text(
"Forest",
style: GoogleFonts.merriweather(
color: Colors.white,
fontSize: 25,
),
),
SizedBox(
width: 25,
),
Icon(Icons.graphic_eq,
size: 30, color: Colors.white),
],
),
IconButton(
onPressed: () {
playAudio();
},
icon: Icon(
Icons.play_circle,
size: 60,
color: Colors.white,
)),
SizedBox(
height: 120,
),
],
),
)
],
),
),
),
),
),
);
}
}
how can I make the sound play can you help me this is the whole probleme