📜  颤振从资产中获取图像文件 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:48.544000             🧑  作者: Mango

代码示例1
import 'dart:async';
import 'dart:io';

import 'package:flutter/services.dart' show rootBundle;
import 'package:path_provider/path_provider.dart';

Future getImageFileFromAssets(String path) async {
  final byteData = await rootBundle.load('assets/$path');

  final file = File('${(await getTemporaryDirectory()).path}/$path');
  await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));

  return file;
}

File f = await getImageFileFromAssets('images/myImage.jpg');