我在 Android Studio 上运行任何 flutter 项目,它会引发内存不足错误。控制台中显示的消息如下所示:
e:\b\build\slave\windows_engine\build\src\third_party\dart\runtime\vm\scavenger.cc: 411: error: Out of memory.
Dumping native stack trace for thread 2750
[0x00007ff676324b63] Dart_IsPrecompiledRuntime
[0x00007ff676324b63] Dart_IsPrecompiledRuntime
-- End of DumpStackTrace
考虑以下build()函数:
Widget build(BuildContext context){
return MaterialApp(
home: Scaffold(
body: Center(
child: ListView.builder(
itemCount: 6,
itemBuilder: (context, i){
if(numberTruthList[i]){
return ListTile(
title: Text("$i"),
);
}
},
),
)
),
);
}
Run Code Online (Sandbox Code Playgroud)
如果 numberTruthList 是
List<bool> numberTruthList = [true, true, true, true , true, true];
然后输出是
如果 numberTruthList 是
List<bool> numberTruthList = [false, true, true, true , true, true];
输出结果是
我希望输出是带有项目的 ListView
ListTile( title: Text("$i"),);
Run Code Online (Sandbox Code Playgroud)
对于 i 的值,使得 numberTruthList[i] 为真,代码应该是什么?
点击按钮时将显示一个alertDialog,并在几秒钟后自动消失。如何在Flutter中做到这一点?
我尝试添加5 BottomNavigationBarItem,但是,如果我尝试添加3个以上的项目,则编译器将引发错误。看起来像这样:
The following RangeError was thrown building BottomNavigationBar(dirty, state:
_BottomNavigationBarState#a56dd(tickers: tracking 3 tickers)):
RangeError (index): Invalid value: Not in range 0..2, inclusive: 3
Run Code Online (Sandbox Code Playgroud)
我需要在BottomNavigationBar中显示5个项目。帮我解决这个问题。
有指向代码的链接,当前那里只有三个项目,我想再添加两个项目,而编译器不会抛出错误消息
在定义构造函数时,是否可以将常量值分配给数据类型List的可选参数。例如,
`class sample{
final int x;
final List<String> y;
sample({this.x = 0; this.y = ["y","y","y","y"]});
}`
Run Code Online (Sandbox Code Playgroud)
上面的代码抛出了一个针对y赋值的错误: Default values of an optional parameter must be constant
此错误的原因是什么?我还可以如何为列表分配默认值?
“包含:-1”在范围错误中是什么意思
RangeError (index): Invalid Value: Not in range 0..6, inclusive: -1
注意:索引是来自
ListView.builder(
itemBuilder: (context,index) => Widget,
)
Run Code Online (Sandbox Code Playgroud)