【问题标题】:Flutter - Base64 class not foundFlutter - 找不到 Base64 类
【发布时间】:2019-03-23 09:40:43
【问题描述】:

我有点怀疑也许你能帮助我。问题如下: 我正在 Flutter 中创建一个实体(产品),本地数据存储在 json 中。实体有三个图像, 我从文件转换为 Base64 并将它们放入 json ... 由于这个原因,json增长了很多,但我想尽可能地重现 一旦我使用包含存储在 Base64 中的图像的 BD SQlite,应用程序应该做出反应的场景。 正如您在一些示例中看到的,最好声明我将图像保存为 Uint8List 的属性 然后使用方法: Image.memory(product.mainImage) 将获取图像。但是当我尝试调用 Base64 类我找不到它,当我把导入应该放在类的位置时,VSCode告诉我“导入” 未使用...并建议我将其删除。感谢您的关注,希望您能帮到我。

我的杰森

{
 "products" : [
 {
  "id" : 1, 
  "name":"Perfumes y aseo personal",
  "description" : "Perfumes y aseo personal",
  "mainImage": "/9j/4AAQSkZJRgABAQEAYABgAAD....",
  "firstImage": "/9j/4AAQSkZJRgABAQAAAQABA...",
  "secondImage": "/9j/4AAQSkZJRgABAQEAYABgA..." 
 },
 .....

我的代码

import 'dart:async';
import 'dart:typed_data';

class Product {

 int id;
 String name;
 String description;
 Uint8List mainImage;
 Uint8List firstImage;
 Uint8List secondImage;

 Product({this.id,this.name,this.description,this.mainImage,this.firstImage,this.secondImage});

 Product.fromMap(Map<String,dynamic> map)
 :id = map["id"],
  name = map["name"],
  description = map["description"],
  mainImage = No found -> Base64.decode(map["main_image"]), 
  firstImage = No found -> Base64.decode(map["first_image"]),
  secondImage = No found -> Base64.decode(map["second_image"]);

}

【问题讨论】:

标签: android dart flutter


【解决方案1】:

您必须导入dart:convert 并使用base64 而不是Base64

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-03
    • 1970-01-01
    • 2020-10-05
    • 2020-07-05
    • 2018-08-16
    • 2023-03-31
    • 2021-06-10
    相关资源
    最近更新 更多