flutter pub.dev - 我的软件包没有正确显示平台(网页丢失)

4dbbbstv  于 2023-01-21  发布在  Flutter
关注(0)|答案(1)|浏览(163)

我开发了一个Flutter包multi_image_picker_viewhttps://pub.dev/packages/multi_image_picker_view
此软件包依赖于file_pickerflutter_reorderable_grid_view它们都支持Web。但在我的软件包中,Web选项在pub.dev中不可见。即使此软件包在Web上也能正常工作
👉* 帮我弄清楚为什么Web没有显示在pub.dev上 *

📜我的酒吧规范yaml

name: multi_image_picker_view
description: A complete widget that can easily pick multiple images from a device and display them in UI. Also picked image can be re-ordered and removed easily.
version: 0.0.6
homepage: https://github.com/shubham-gupta-16/multi_image_picker_view
repository: https://github.com/shubham-gupta-16/multi_image_picker_view
issue_tracker: https://github.com/shubham-gupta-16/multi_image_picker_view/issues

environment:
  sdk: ">=2.17.1 <3.0.0"
  flutter: ">=1.17.0"

dependencies:
  flutter:
    sdk: flutter

  flutter_reorderable_grid_view: ^3.1.3
  file_picker: ^5.0.1

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0

flutter:
  assets:
    - packages/multi_image_picker_view/assets/close-48.png

👨‍💻用于发布的命令

flutter pub publish

🗃️我的火柴信息

  • Flutter版本:3.0.1
  • 通道:稳定
  • Dart版本:2.17.1
  • 集成开发环境:Android Studio花栗鼠|2021.2.1补丁程序1

🚀您可以找到完整的代码Github:https://github.com/shubham-gupta-16/multi_image_picker_view
先谢谢你。

9jyewag0

9jyewag01#

需要条件导入

这个包在pub.dev上不显示Web的原因是它使用了没有条件导入的dart.io
为了解决这个问题,我将文件的使用位置分开,一个用于Web平台,一个用于非Web平台,然后根据运行平台的条件导入它们。

网页预览.dart

import 'package:flutter/material.dart';

import '../image_file.dart';

class ImagePreview extends StatelessWidget {
  final ImageFile file;

  const ImagePreview({Key? key, required this.file}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(4),
      child: Image.memory(
        file.bytes!,
        fit: BoxFit.cover,
        errorBuilder: (context, error, stackTrace) {
          return const Center(child: Text('No Preview'));
        },
      ),
    );
  }
}

非网页预览.dart

import 'dart:io'; // here I imported dart:io
import 'package:flutter/material.dart';
import '../image_file.dart';

class ImagePreview extends StatelessWidget {
  final ImageFile file;

  const ImagePreview({Key? key, required this.file}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(4),
      child: Image.file(
        File(file.path!), // Now I can use File class
        fit: BoxFit.cover,
      ),
    );
  }
}

我的包文件.dart

...
import 'non_web_preview.dart' if (dart.library.html) 'web_preview.dart'; // conditional import

class MyPackageFile extends StatelessWidget {
  ...
  
  @override
  Widget build(BuildContext context) {
    return ImagePreview(file: imageFile); // Using ImagePreview class
  }
}

相关问题