0
import 'package:image/image.dart' as img;   

List<Book> _items = [
        Book(
          id: 'b0',
          title: 'Subtle Art',
          authors: ['Mark Manson'],
          coverImage:
              img.decodeJpg(new File('assets/Subtle Art.jpg').readAsBytesSync()),
        )
      ];

error no 2 is showing: No such file or directory exists But there is assets folder with the image file in root folder and in pubspec.yaml both

assets:
- 'assets/Subtle Art.jpg'
  • did you try using removing space from image name ? like `Subtle_Art.jpg` – Aamil Silawat Sep 02 '20 at 13:38
  • assume that you've put the path in pubspec.yaml corectly, try flutter clean, restart vscode or whatever editor you're using and run flutter pub get – Dung Ngo Sep 03 '20 at 01:46

1 Answers1

0

In flutter you unfortunately can't directly access the "assets" directory. If you want to consume assets this is the proper way to do it: https://flutter.dev/docs/development/ui/assets-and-images

I recommend you to also use https://pub.dev/packages/path_provider to access to anywhere else on your phone.

Mike
  • 348
  • 2
  • 8