[英]flutter error : RangeError (index): Invalid value: Valid value range is empty: 0
The project I pulled from github flutter run Successfully我从github上拉的项目flutter运行成功
but the page did not draw the wave of data但是页面没有画出一波数据
(elided 3 frames from dart:async)
The following RenderObject was being processed when the exception was fired: RenderClipPath#2d7dd relayoutBoundary=up5
RenderObject: RenderClipPath#2d7dd relayoutBoundary=up5
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=674.9)
size: Size(392.7, 392.7)
child: RenderConstrainedBox#cc534 relayoutBoundary=up6 NEEDS-PAINT
parentData: <none> (can use size)
constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=674.9)
size: Size(392.7, 392.7)
additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=392.7)
gradient: LinearGradient(begin: Alignment.centerLeft, end: Alignment.centerRight, colors: [Color(0xfffeac5e), Color(0xffc779d0), Color(0xff4bc0c8)], stops: [0.1, 0.3, 0.9], tileMode: TileMode.clamp)
configuration: ImageConfiguration(bundle: PlatformAssetBundle#2c6f4(), devicePixelRatio: 2.8, locale: en_US, textDirection: TextDirection.ltr, platform: android)
child: RenderLimitedBox#7ca4f relayoutBoundary=up8 NEEDS-PAINT
parentData: <none> (can use size)
constraints: BoxConstraints(0.0<=w<=392.7, h=392.7)
size: Size(392.7, 392.7)
maxWidth: 0.0
maxHeight: 0.0
child: RenderConstrainedBox#bb55f relayoutBoundary=up9 NEEDS-PAINT
parentData: <none> (can use size)
constraints: BoxConstraints(0.0<=w<=392.7, h=392.7)
size: Size(392.7, 392.7)
additionalConstraints: BoxConstraints(biggest)
this is my CustomPaint and ClipPath这是我的 CustomPaint 和 ClipPath
════════ Exception caught by rendering library ═════════════════════════════════
RangeError (index): Invalid value: Valid value range is empty: 0
The relevant error-causing widget was
CustomPaint and ClipPath
children: <Widget>[
CustomPaint(
size: Size(
constraints.maxWidth,
height,
),
foregroundPainter: WaveformPainter(
widget.sampleData,
zoomLevel: zoomLevel,
startingFrame: widget.sampleData
.frameIdxFromPercent(startPosition),
color: Color(0xff3994DB),
),
),
ClipPath(
clipper: WaveformClipper(snapshot.data!),
child: Container(
height: height,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
stops: [0.1, 0.3, 0.9],
colors: [
Color(0xffFEAC5E),
Color(0xffC779D0),
Color(0xff4BC0C8),
],
),
),
),
);
this is my flutter doctor这是我的颤振医生
[√] Flutter (Channel stable, 3.0.0, on Microsoft Windows [10.0.19044.1706], locale zh-Hans-HK)
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[X] Visual Studio - develop for Windows
X Visual Studio not installed; this is necessary for Windows development.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2021.2)
[√] Connected device (3 available)
[√] HTTP Host Availability
this is my WaveformData._scaleData这是我的 WaveformData._scaleData
_scaleData() {
final max = pow(2, bits! - 1).toDouble();
final dataSize = data?.length;
_scaledData = [];
for (var i = 0; i < dataSize!; i++) {
_scaledData![i] = data![i].toDouble() / max;
if (_scaledData![i] > 1.0) {
_scaledData![i] = 1.0;
}
if (_scaledData![i] < -1.0) {
_scaledData![i] = -1.0;
}
}
}
}
this is my WaveformData.path这是我的 WaveformData.path
Path path(Size size, {zoomLevel = 1.0, int fromFrame = 0}) {
if (!_isDataScaled()) {
_scaleData();
}
this is my WaveformClipper.getClip这是我的 WaveformClipper.getClip
lass WaveformClipper extends CustomClipper<Path> {
WaveformClipper(this.data);
final WaveformData? data;
@override
Path getClip(Size size) {
return data!.path(size);
}
@override
bool shouldReclip(WaveformClipper oldClipper) {
if (data != oldClipper.data) {
return true;
}
return false;
}
} }
You need to null check here.您需要在此处进行空检查。 Probably dataSize is null.
可能 dataSize 为空。 You need to do like this.
你需要这样做。
if(dataSize != null){
for (var i = 0; i < dataSize!; i++) {
_scaledData![i] = data![i].toDouble() / max;
if (_scaledData![i] > 1.0) {
_scaledData![i] = 1.0;
}
if (_scaledData![i] < -1.0) {
_scaledData![i] = -1.0;
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.