flutter - 在颤动中创建了不必要的对象并占用了内存
问题描述
我有一个颤振应用程序,我在其中安装了一个 qr_flutter 包来呈现二维码。我的应用程序在加载时登陆登录屏幕,并且我没有使用任何与二维码相关的东西。当我打开 DevTools 并在内存视图中拍摄快照时,我可以看到一些对象已创建并占用与包 qr_flutter 相关的内存。
FinderPatternPosition
QrCodeElement
QrValidationStatus
qr_flutter 包中有枚举。有关他包的更多详细信息https://pub.dev/documentation/qr_flutter/latest/qr_flutter/qr_flutter-library.html
问题是为什么要创建这些对象?这就是包在颤振中安装后的工作方式吗?
解决方案
是的。这些Enums
定义在types.dart
. 你可以参考源代码
并paint_cache.dart
使用那些枚举https://github.com/lukef/qr.flutter/blob/master/lib/src/paint_cache.dart
QrValidationStatus
在
https://github.com/lukef/qr.flutter/blob/master/lib/src/validator.dart中定义
/// The status of the QR code data you requested to be validated.
enum QrValidationStatus {
/// The QR code data is valid for the provided parameters.
valid,
/// The QR code data is too long for the provided version + error check
/// configuration or too long to be contained in a QR code.
contentTooLong,
/// An unknown / unexpected error occurred when we tried to validate the QR
/// code data.
error,
}
FinderPatternPosition
并QrCodeElement
在https://github.com/lukef/qr.flutter/blob/master/lib/src/types.dart中定义
/*
* QR.Flutter
* Copyright (c) 2019 the QR.Flutter authors.
* See LICENSE for distribution and usage details.
*/
import 'dart:ui';
import 'package:flutter/widgets.dart';
/// Represents a specific element / part of a QR code. This is used to isolate
/// the different parts so that we can style and modify specific parts
/// independently.
enum QrCodeElement {
/// The 'stroke' / outer square of the QR code finder pattern element.
finderPatternOuter,
/// The inner/in-between square of the QR code finder pattern element.
finderPatternInner,
/// The "dot" square of the QR code finder pattern element.
finderPatternDot,
/// The individual pixels of the QR code
codePixel,
/// The "empty" pixels of the QR code
codePixelEmpty,
}
/// Enumeration representing the three finder pattern (square 'eye') locations.
enum FinderPatternPosition {
/// The top left position.
topLeft,
/// The top right position.
topRight,
/// The bottom left position.
bottomLeft,
}
/// Styling options for any embedded image overlay
class QrEmbeddedImageStyle {
/// Create a new set of styling options.
QrEmbeddedImageStyle({
this.size,
this.color,
});
/// The size of the image. If one dimension is zero then the other dimension
/// will be used to scale the zero dimension based on the original image
/// size.
Size size;
/// Color to tint the image.
Color color;
/// Check to see if the style object has a non-null, non-zero size.
bool get hasDefinedSize => size != null && size.longestSide > 0;
@override
int get hashCode => size.hashCode ^ color.hashCode;
@override
bool operator ==(Object other) {
if (other is QrEmbeddedImageStyle) {
return size == other.size && color == other.color;
}
return false;
}
}
推荐阅读
- javascript - 错误:对象作为 React 子项无效(找到:带有键 {rank} 的对象)。如果您打算渲染一组孩子,请改用数组
- javascript - Adobe 中的脚本 - 如何将字段转换为另一种类型
- command-line-interface - 如何为 Raku CLI 使用包装脚本
- python-3.x - PySocks 和 imaplib/smtplib 禁止出现错误 403
- reactjs - 如何将 cron 作业设置为在一周中的特定日期每两周运行一次
- kotlin - 如何在没有 Kotlin 源代码的情况下在 Espresso 中启动活动?
- sql - 具有多对多关系且必须满足一个条件的 2 个表的 SQL 查询
- asp.net-core - ASP.NET Core Web API 仅返回一条验证错误消息
- python - 如何在 Python 中从这个函数中获得一些回报?
- elixir - 错误:elixir_make 0.6.1 已退休!(无效)mix.exs 文件的权限错误