diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index add7322b3a..aec03e94c6 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -283,7 +283,7 @@ class HotRunner extends ResidentRunner { } Future _updateDevFS({ bool fullRestart = false }) async { - final bool isFirstUpload = assetBundle.wasBuiltOnce() == false; + final bool isFirstUpload = !assetBundle.wasBuiltOnce(); final bool rebuildBundle = assetBundle.needsBuild(); if (rebuildBundle) { printTrace('Updating assets'); @@ -308,7 +308,7 @@ class HotRunner extends ResidentRunner { bundle: assetBundle, firstBuildTime: firstBuildTime, bundleFirstUpload: isFirstUpload, - bundleDirty: isFirstUpload == false && rebuildBundle, + bundleDirty: !isFirstUpload && rebuildBundle, fullRestart: fullRestart, projectRootPath: projectRootPath, pathToReload: getReloadPath(fullRestart: fullRestart), @@ -1045,6 +1045,14 @@ class ProjectFileInvalidator { @required List urisToMonitor, @required String packagesPath, }) { + assert(urisToMonitor != null); + assert(packagesPath != null); + + if (lastCompiled == null) { + assert(urisToMonitor.isEmpty); + return []; + } + final List invalidatedFiles = []; int scanned = 0; final Stopwatch stopwatch = Stopwatch()..start(); @@ -1057,17 +1065,13 @@ class ProjectFileInvalidator { final DateTime updatedAt = fs.statSync( uri.toFilePath(windows: platform.isWindows)).modified; scanned++; - if (updatedAt == null) { - continue; - } - if (updatedAt.millisecondsSinceEpoch > lastCompiled.millisecondsSinceEpoch) { + if (updatedAt != null && updatedAt.isAfter(lastCompiled)) { invalidatedFiles.add(uri); } } - // we need to check the .packages file too since it is not used in compilation. + // We need to check the .packages file too since it is not used in compilation. final DateTime packagesUpdatedAt = fs.statSync(packagesPath).modified; - if (lastCompiled != null && packagesUpdatedAt != null - && packagesUpdatedAt.millisecondsSinceEpoch > lastCompiled.millisecondsSinceEpoch) { + if (packagesUpdatedAt != null && packagesUpdatedAt.isAfter(lastCompiled)) { invalidatedFiles.add(fs.file(packagesPath).uri); scanned++; } diff --git a/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart b/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart index d25ef6d4d5..b5c8c02bfd 100644 --- a/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart +++ b/packages/flutter_tools/test/general.shard/project_file_invalidator_test.dart @@ -12,6 +12,12 @@ import '../src/context.dart'; void main() { group('ProjectFileInvalidator', () { final MemoryFileSystem memoryFileSystem = MemoryFileSystem(); + testUsingContext('No last compile', () async { + expect( + ProjectFileInvalidator.findInvalidated(lastCompiled: null, urisToMonitor: [], packagesPath: ''), + isEmpty); + }); + testUsingContext('Empty project', () async { expect( ProjectFileInvalidator.findInvalidated(lastCompiled: DateTime.now(), urisToMonitor: [], packagesPath: ''),