whenver I run my application, I run into this error in errors_patch.dart
external static Never _throw(Object error, StackTrace stackTrace);
here is my entire file if it helps
import 'dart:convert';
import 'dart:io';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';
import 'package:path_provider/path_provider.dart';
class PlayAudioBookScreen extends StatefulWidget {
final Map<String, dynamic> initialChapterData;
final Map<String, dynamic> audioBookData;
const PlayAudioBookScreen(this.initialChapterData, this.audioBookData, {super.key});
@override
State<PlayAudioBookScreen> createState() => PlayAudioBookScreenState();
}
class PlayAudioBookScreenState extends State<PlayAudioBookScreen> {
AudioPlayer player = AudioPlayer();
bool playing = true;
double sliderPos = 0;
String bookTitle = "";
String chapterTitle = "";
String author = "";
String audioFileLocalPath = "";
String audioFileFirebasePath = "";
int audioFileDuration = 0; // is in milliseconds
Map<String, dynamic> currentChapterData = jsonDecode("{}");
// in the below, bear in mind im limited by the variables (and equivalently the parameters) of the
// PlayAudioBookScreen class must be final, so i cant just update the chapterData variable to the
// next chapters data when reaching the end of the file.
// a possible way of modifying the current chapter data used by the widget on the fly is by doing what
// ive done with the commented out chapterData2 variable below here. just make a chapterData2 variable
// like this, initialize it to widget.chapterData inside initState(), and then update it to the next
// chapters data when reaching the end of the file.
// other options would be to pop this screen and push a new one with the next chapters data, or to
// have some global state management system like provider or bloc that i can consult to ask what
// chapter where on now.
// or even just provide the chapter number as a parameter called startChapter or sth, and inside the
// state class have a "currentChapter" variable that is initialized to startChapter, and then updated
// accordingly, and just get the chapter data of the currentChapter variable from audioBookData on an
// adhoc basis.
@override
void initState() {
bookTitle = widget.audioBookData["title"];
author = widget.audioBookData["author"];
currentChapterData = widget.initialChapterData;
chapterTitle = currentChapterData["title"];
audioFileLocalPath = currentChapterData["localPath"];
audioFileFirebasePath = currentChapterData["firebasePath"];
setupPlayer();
super.initState();
}
void setupPlayer() async {
Directory appDocDir = await getApplicationDocumentsDirectory();
File audioFile = File("${appDocDir.path}/$audioFileLocalPath");
if (!await audioFile.exists()) {
// should have some error handling here if the download is unsuccessful in case the user is online,
// maybe in other places of the app too <skull emoji>
audioFile.create(recursive: true);
print("come in here3");
Reference audioFileFirebaseRef = FirebaseStorage.instance.ref(audioFileFirebasePath);
await audioFileFirebaseRef.writeToFile(audioFile);
}
await player.setUrl(audioFile.path);
player.createPositionStream();
audioFileDuration = player.duration!.inMilliseconds;
player.positionStream.listen((position) {
if (position.inMilliseconds >= audioFileDuration) {
if (int.parse(currentChapterData["chapterNumber"]) < widget.audioBookData["chapters"].length) {
print("come in here");
int nextChapterNumber = int.parse(currentChapterData["chapterNumber"]) + 1;
print("I see this print statement");
setupNewChapter(widget.audioBookData["chapters"][nextChapterNumber]);
} else {
print("acc here");
player.pause();
setState(() {
sliderPos = audioFileDuration.toDouble();
playing = false;
});
}
} else {
setState(() {
sliderPos = position.inMilliseconds.toDouble();
});
}
});
player.play();
setState(() {
playing = true;
});
}
void setupNewChapter(Map<String, dynamic> chapterData) {
print("but dont see this print statement");
currentChapterData = chapterData;
print("come in here3");
chapterTitle = currentChapterData["title"];
print("come in her4S");
audioFileLocalPath = currentChapterData["localPath"];
print("come in here2");
audioFileFirebasePath = currentChapterData["firebasePath"];
print("come in here2");
setupPlayer();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(children: [
const SizedBox(height: 80),
Text(bookTitle, style: const TextStyle(fontWeight: FontWeight.bold)),
Text(chapterTitle, style: const TextStyle(fontWeight: FontWeight.bold)),
Text("by $author"),
const SizedBox(height: 20),
playing
? IconButton(
icon: const Icon(Icons.pause),
onPressed: () async {
player.pause();
setState(() {
playing = false;
});
},
)
: IconButton(
icon: const Icon(Icons.play_arrow),
onPressed: () async {
player.play();
setState(() {
playing = true;
});
},
),
Slider(
min: 0,
max: audioFileDuration.toDouble(),
value: sliderPos,
onChanged: (value) async {
await player.seek(Duration(milliseconds: value.toInt()));
}),
]),
);
}
}
but there doesn't seem to be any explanation online that I can find as to what this error means. I have put print statements and I see up to the print statement that says "I see this print statement" but then I dont see the one that says "but I dont see this one"