Flutter应用程序由于使用palette_generator软件包而崩溃

时间:2019-11-26 19:17:48

标签: android performance flutter dart stream

我正在尝试获取图像的最主要颜色并将其放置在该特定小部件的背景中。

为了选择正确的颜色,我使用了palette_generator包装。我在无状态小部件中使用它,该小部件获取图像。包装应选择一种颜色并将其放在背景中。

但是每次我使用软件包时,应用都会崩溃,并显示以下错误:

W/libc    ( 2453): malloc(105781228) failed: returning null pointer
F/libc    ( 2453): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 2518 (1.io), pid 2453 (.my_flutter_app)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/sdk_gphone_x86/generic_x86:10/QSR1.190920.001/5891938:user/release-keys'
Revision: '0'
ABI: 'x86'
      #02 pc 0112cf66  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #03 pc 0112cca1  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #04 pc 01114729  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #05 pc 01116ce8  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #06 pc 01116c2a  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #07 pc 0111d678  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #08 pc 0111d6a6  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #09 pc 00018487  /system/lib/libutils.so (android::SimpleLooperCallback::handleEvent(int, int, void*)+39) (BuildId: 288ba3aff5b46dbd7e74be954af88b83)
      #10 pc 00019414  /system/lib/libutils.so (android::Looper::pollInner(int)+1044) (BuildId: 288ba3aff5b46dbd7e74be954af88b83)
      #11 pc 00018f4e  /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+62) (BuildId: 288ba3aff5b46dbd7e74be954af88b83)
      #12 pc 00013780  /system/lib/libandroid.so (ALooper_pollOnce+96) (BuildId: 2b4362d3e0db6d6e8fbea7ad8414fbae)
      #13 pc 0111d5b5  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #14 pc 01116bd8  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #15 pc 0111674a  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #16 pc 0111accf  /data/app/com.timecreators.my_flutter_app-4a1YPZl4Xc0RjxeRy4V8ag==/lib/x86/libflutter.so (BuildId: 7ca566457ac4b7d6)
      #17 pc 0011a8e5  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+53) (BuildId: 76290498408016ad14f4b98c3ab6c65c)
      #18 pc 000af6a7  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71) (BuildId: 76290498408016ad14f4b98c3ab6c65c)
Lost connection to device.

当我使用以下流函数时,会发生此错误:

PaletteGenerator paletteGenerator;
  Rect imageRegion = Offset.zero & Size(50, 50);

  Stream<Color> getImageColor() async* {
    paletteGenerator = await PaletteGenerator.fromImageProvider(
      this.image.image,
      size: Size(50, 50),
      region: imageRegion,
      maximumColorCount: 5,
    );

    yield paletteGenerator.paletteColors[1].color.withOpacity(0.1);
  }

这就是我正在使用palette_generator的整个小部件:

import 'package:flutter/material.dart';
import 'package:my_flutter_app/styles/Themes.dart';
import 'package:palette_generator/palette_generator.dart';

class DiskItem extends StatelessWidget {
  final String name;
  final Image image;
  final int price;
  DiskItem({
    @required this.name,
    @required this.image,
    @required this.price,
  })  : assert(name.trim().length > 0),
        assert(image != null);

  var themes = Themes();
  PaletteGenerator paletteGenerator;
  Rect imageRegion = Offset.zero & Size(50, 50);

  Stream<Color> getImageColor() async* {
    paletteGenerator = await PaletteGenerator.fromImageProvider(
      this.image.image,
      size: Size(50, 50),
      region: imageRegion,
      maximumColorCount: 5,
    );

    yield paletteGenerator.paletteColors[1].color.withOpacity(0.1);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 244,
      width: 155,
      child: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Container(
              height: 100,
              width: 100,
              child: Stack(
                overflow: Overflow.visible,
                children: <Widget>[
                  StreamBuilder<Color>(
                    stream: getImageColor(),
                    initialData: Colors.grey.withOpacity(0.1),
                    builder: (context, snapshot) {
                      return Container(
                        height: 125,
                        width: 125,
                        decoration: BoxDecoration(
                          color: snapshot.data,
                          borderRadius: BorderRadius.circular(15),
                        ),
                      );
                    },
                  ),
                  Positioned(
                    top: 20.0,
                    right: 15.0,
                    child: Container(
                      height: 100,
                      width: 100,
                      child: image,
                    ),
                  )
                ],
              ),
            ),
            SizedBox(
              height: 5,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  "ab",
                  style: themes.diskItemPricePrefix,
                ),
                Text("$price€", style: themes.diskItemPrice),
              ],
            ),
            Text(
              name,
              style: themes.diskItemTitle,
            )
          ],
        ),
      ),
    );
  }
}

我发现这是通过一个简单的测试导致了palette_generator包的产生:我在streambuilder中放置了另一个stream函数。这样,它就可以顺利运行。

我希望有人能够帮助我。

0 个答案:

没有答案