How to read bytes of a local image file in Dart/Flutter?

前端 未结 3 758
时光说笑
时光说笑 2021-01-11 19:42

I would like to use a placeholder image file that I\'ve added to my code as \"assets/placeholder.png\", but I\'m getting a File not found error. This is how I\

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-11 19:57

    With Flutter environment, you have to use AssetBundle if you want to access to your assets (https://flutter.io/assets-and-images/).

    import 'package:flutter/services.dart' show rootBundle;
    
    
    ByteData bytes = await rootBundle.load('assets/placeholder.png');
    

提交回复
热议问题