2424import org .jetbrains .annotations .NotNull ;
2525import org .jetbrains .annotations .Nullable ;
2626
27+ import java .io .File ;
2728import java .util .List ;
2829import java .util .Map ;
2930
@@ -281,7 +282,6 @@ public VirtualFile getPackagesFile() {
281282 if (packages != null && !packages .isDirectory ()) {
282283 return packages ;
283284 }
284-
285285 return null ;
286286 }
287287
@@ -300,19 +300,27 @@ public VirtualFile getPackagesFile() {
300300 }
301301
302302 /**
303- * Returns true if the packages are up to date wrt pubspec.yaml.
303+ * Returns true if the packages are up-to-date with regard to the `pubspec.yaml`. The `.packages` file is used if no
304+ * `.tool/package_config.json` is found. The default value returned is to return false.
304305 */
305306 public boolean hasUpToDatePackages () {
307+ // See context at these URLs for the reason we can't use VirtualFile#getTimeStamp()
308+ // https://github.com/flutter/flutter-intellij/issues/7538
309+ // https://intellij-support.jetbrains.com/hc/en-us/community/posts/8009750602514-VirtualFile-is-not-refreshed
310+
306311 final VirtualFile configFile = getPackageConfigFile ();
307312 if (configFile != null ) {
308- return pubspec .getTimeStamp () < configFile .getTimeStamp ();
313+ long pubspecLastModified = new File (pubspec .getPath ()).lastModified ();
314+ long configLastModified = new File (configFile .getPath ()).lastModified ();
315+ return pubspecLastModified < configLastModified ;
309316 }
310317 final VirtualFile packagesFile = getPackagesFile ();
311- if (packagesFile == null ) {
312- return false ;
318+ if (packagesFile != null ) {
319+ long pubspecLastModified = new File (pubspec .getPath ()).lastModified ();
320+ long packagesLastModified = new File (packagesFile .getPath ()).lastModified ();
321+ return pubspecLastModified < packagesLastModified ;
313322 }
314-
315- return pubspec .getTimeStamp () < packagesFile .getTimeStamp ();
323+ return false ;
316324 }
317325
318326 @ Nullable
0 commit comments