错误:NoSuchMethodError:在null上调用吸气剂“长度”

时间:2020-06-08 14:22:36

标签: android flutter share

当我按下共享按钮(_shareImageFromUrl)时,出现了此错误。我在pubspec.yaml中具有以下依赖性。

cached_network_image:^ 2.2.0 + 1 flutter_cache_manager:^ 1.4.0

我的代码如下

error : 

I/flutter ( 9233): error: NoSuchMethodError: The getter 'length' was called on null.
I/flutter ( 9233): Receiver: null
I/flutter ( 9233): Tried calling: length



Future<void> _shareImageFromUrl() async {
      try {
          var request = await HttpClient().getUrl(Uri.parse(
              'https://shop.esys.eu/media/image/6f/8f/af/amlog_transport-berwachung.jpg'));
          var response = await request.close();
          var bytes = await consolidateHttpClientResponseBytes(response);
          await Share.file('ESYS AMLOG', 'amlog.jpg', bytes, 'image/jpg');
        } catch (e) {
          print('error: $e');
        }
      }

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text("Hello Appbar"),

        actions: <Widget>[
          MaterialButton(
            child: Text('Share image from url'),
            onPressed: () async => await _shareImageFromUrl(),
          ),
          Padding(
            padding: EdgeInsets.only(right: 20.0),
            child: GestureDetector(
              onTap: () => _test("abc"),
              child: Icon(
                Icons.share,
                size: 26.0,
              ),
            )
          ),
        ],
    ),
    body: myImage == null ? Center(child: CircularProgressIndicator()) : _getImage(),
    drawer: GoodMorningDrawer(),
  );
}

请大家帮我

0 个答案:

没有答案