'give an initial value to the type File in flutter

hi every one I need to give an initial value to the type File in flutter language such as this var File _profileImage = ; what I should put after the = . I don't want use this format File? _profileImage;



Solution 1:[1]

A File object doesn't do anything until you perform an operation on it (such as trying to open, read from, or write to the underlying file on the filesystem). Therefore, if you really want, you could do var _profileImage = File(''); and check _profileImage.path.isNotEmpty everywhere later. (For POSIX systems, you also could consider File('/dev/null'), which wouldn't fail if you attempt to read from or write to it.)

However, that is arguably not any better than using File? with a null default. Using a File? would allow Dart's type system to catch any places where you neglect to check for that bogus initial value at compile-time.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jamesdlin