I have a Flutter application where I retrieve data from local storage. Some of this data can be deleted by the user within the application. However, when the application is restarted, the deleted data reappears. Additionally, the data is also deleted from local storage. Why does the application reload the same data again after restart?
I’m experiencing an issue in my Flutter application where, despite deleting data and removing it from the local storage, the deleted data reappears upon application restart. The provided code handles the deletion of data from both the application state and local storage. Could someone help me understand why the deleted data is reloading upon application restart and how to prevent this behavior?
Future<void> getFilePath(String filePath, BuildContext context, int index) async {
try {
if (await File(filePath).exists()) {
index = Provider.of<PlayerStateles>(context, listen: false).currentIndex;
Provider.of<GetMusicProvider>(context, listen: false).musicList.removeAt(index);
await File(filePath).delete();
await Provider.of<PlayerStateles>(context, listen: false)
.updateCurrentIndex(index + 1);
Provider.of<MusicPlayerController>(context, listen: false).playOrPause(
index + 1,
Provider.of<GetMusicProvider>(context, listen: false)
.musicList[index + 1]
.uri
.toString()
);
notifyListeners();
} else {
}
} catch (error) {
log(error.toString());
}
}
AndroidManifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>
<activity
android:name="com.ryanheise.audioservice.AudioServiceActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|
screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:requestLegacyExternalStorage='true'
android:allowBackup="false"
android:fullBackupOnly="false"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>