Directory comparison not working in Dart?


Why directory comparison does not work the expected way in Dart?

import 'dart:io';

void main() {
  Directory d = Directory('/kek');
  Directory e = Directory('/kek');
  print(d==e);  // false
  print(d.hashCode);  // 123456
  print(e.hashCode);  // 654321


As I read the documentation for the Directory object, the hashCode and operator== methods are simply inherited from Object, and thus have no special implementation that would cause two different Directory objects to compare equal if they point to the same place.

This would be difficult to implement. Should the hashCode canonicalize relative paths and paths containing “.” and “..”? Should it follow symlinks? What about files with multiple hard links?

Answered By – Lee Daniel Crocker

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *