I just upgraded to latest flutter version 2.2, and now this piece of code is not working.

import 'dart:io';  //this line is greyed out now
file = File("${dir.path}/file.pdf"); //error: Abstract classes can't be instantiated.

I checked the release notes, and could not locate any breaking changes regarding this. The Documentaion shows the File class as abstract, and still the example says:

var myFile = File('file.txt');

What should be the alternative to replace this line?

Solution 1: Shrestha Bibash

Step 1: flutter clean Step 2: Invalidate Caches/Restart

Solution 2: MJ Khan

The issue was with flutter_cache_manager plugin, which I was importing as

import 'package:flutter_cache_manager/flutter_cache_manager.dart';

So I replaced it with

import 'package:flutter_cache_manager/flutter_cache_manager.dart' as FCM;

(Internally this plugin has a line saying:

export 'package:file/file.dart' show File;

) that caused the issue.

Solution 3: p2kr

Check for other imports using File class. You can use alias if its necessary.