MJ Khan
MJ Khan

Reputation: 1746

Dart - What happened to File (dart:io) in Flutter 2.2

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?

Upvotes: 0

Views: 609

Answers (3)

p2kr
p2kr

Reputation: 604

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

Upvotes: 1

MJ Khan
MJ Khan

Reputation: 1746

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.

Upvotes: 0

Shrestha Bibash
Shrestha Bibash

Reputation: 58

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

Upvotes: 0

Related Questions