我知道官方软件包可以从flutter应用程序共享。
https://pub.dartlang.org/packages/share

它易于共享文本和url,但是我想共享来自服务器的图像,这意味着它采用URL格式,因此可能首先我必须将url转换为图像,然后将图像转换为base64,然后才能共享图像但我正在寻找共享图片+文字+网站的简便方法。

我该如何通过官方共享套餐?还有其他保持良好状态的软件包吗?

最佳答案

Simple Share似乎是您想要的:

    import 'package:flutter/material.dart';
    import 'package:file_picker/file_picker.dart';
    import 'package:simple_share/simple_share.dart';
    import 'package:flutter/services.dart';

    void main() => runApp(SimpleShareApp());

    class SimpleShareApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
            showPerformanceOverlay: false,
            title: 'Simple Share App',
            home: MyHomePage()
        );
      }
    }

    class MyHomePage extends StatefulWidget {
      @override
      _MyHomePageState createState() => new _MyHomePageState();
    }

    class _MyHomePageState extends State<MyHomePage> {
      Future<String> getFilePath() async {
        try {
          String filePath = await FilePicker.getFilePath(type: FileType.ANY);
          if (filePath == '') {
            return "";
          }
          print("File path: " + filePath);
          return filePath;
        } on PlatformException catch (e) {
          print("Error while picking the file: " + e.toString());
          return null;
        }
      }

      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(
            title: new Text('File Picker Example'),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                RaisedButton(
                  onPressed: () {
                    SimpleShare.share(
                      title: "Share my message",
                      msg:
                          "Lorem ipsum dolor sit amet, consectetur adipisci elit, sed eiusmod " +
                              "tempor incidunt ut labore et dolore magna aliqua.",
                    );
                  },
                  child: Text('Share text!'),
                ),
                RaisedButton(
                  onPressed: () async {
                    final path = await getFilePath();
                    if (path != null && path.isNotEmpty) {
                      final uri = Uri.file(path);
                      SimpleShare.share(
                          uri: uri.toString(),
                          title: "Share my file",
                          msg: "My message");
                    }
                  },
                  child: Text('Share file!'),
                ),
              ],
            ),
          ),
        );
      }
    }

Source

关于dart - 在Flutter中分享图片+文字+网址的便捷方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54453247/

10-09 10:18