createFileChangeToken method
Creates a change token for the specified filter pattern.
filter can be:
- A specific file path (e.g., "appsettings.json")
- A glob pattern (e.g., "**/.json", "config/.xml")
- A directory path (e.g., "logs/")
The change token will report changes to any files matching the pattern.
Implementation
IChangeToken createFileChangeToken(String filter) {
if (filter.isEmpty) {
return NullChangeToken();
}
// Normalize the filter path
final normalizedFilter = p.normalize(filter);
// Check if this is a wildcard pattern
if (_isWildcardPattern(normalizedFilter)) {
return _createWildcardToken(normalizedFilter);
}
// Check if this is a directory
final fullPath = p.isAbsolute(normalizedFilter)
? normalizedFilter
: p.join(_root, normalizedFilter);
final entity = FileSystemEntity.typeSync(fullPath);
if (entity == FileSystemEntityType.directory) {
// Watch all files in the directory
return _createWildcardToken(p.join(normalizedFilter, '*'));
}
// Watch a specific file
return _createFileToken(fullPath);
}