I am developing an alarm system in flutter web, I am using Timer.period for paly sound in loop and sound_library for sounds. But It is not working as aspected. Please Suggest me any alternative if possible, It would be very helpful. My code is below:


 int count = 0;
 Timer? timer;

_alert() {
    const timerDuration = Duration(seconds: 3);
    itemCollections
        .doc(dateFormat.format(DateTime.now()))
        .collection("items")
        .snapshots()
        .listen((event) {
      var list =
          event.docs.where((element) => element.data()['status'] == "Awaiting");

      // if (list.isNotEmpty && timer == null) {
      if (list.isNotEmpty && timer == null) {
        timer = Timer.periodic(
            timerDuration, (timer) => SoundPlayer.i.play(Sounds.welcome));
      } else {
        if (timer != null && list.isEmpty) {
          timer!.cancel();
          timer = null;
        }
      }
    });
  }