Android 在dispose()之后调用setState():_StatefulBuilderState#09642(生命周期状态:失效,未装入)
我用底页显示内容,我在计算后更新文件夹大小,使用statefulbuilder的setState,我也使用了mounted condition,然后在调用dispose后显示setState,帮我解决这个问题Android 在dispose()之后调用setState():_StatefulBuilderState#09642(生命周期状态:失效,未装入),android,flutter,dart,async-await,flutter-showmodalbottomsheet,Android,Flutter,Dart,Async Await,Flutter Showmodalbottomsheet,我用底页显示内容,我在计算后更新文件夹大小,使用statefulbuilder的setState,我也使用了mounted condition,然后在调用dispose后显示setState,帮我解决这个问题 FileStat fileStat = selectedFilesAndFolders.last.statSync(); String size = '0 KB'; showModalBottomSheet( context: context, shape:
FileStat fileStat = selectedFilesAndFolders.last.statSync();
String size = '0 KB';
showModalBottomSheet(
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12.0),
topRight: Radius.circular(12.0),
)),
builder: (context) {
return StatefulBuilder(builder: (context, newSetState) {
getFolderSize(selectedFilesAndFolders.last.path).then((value) {
if (!mounted) return;
newSetState(() {
size = value;
});
});
return SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 2.0,
),
Text(
'Info',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 2.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Text('Name: '))),
Expanded(
child: Text(path
.basename(selectedFilesAndFolders.last.path)))
],
),
SizedBox(
height: 2.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Text('Size: '))),
Expanded(child: Text(size)),
],
),
SizedBox(
height: 2.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Text('Last Modified Date: '))),
Expanded(child: Text(fileStat.modified.toString()))
],
),
SizedBox(
height: 2.0,
),
],
),
);
});
});
试试下面的方法
if(!mounted){
设置状态(){
大小=值;
}),
};
如果我使用上述条件,则底部板材打开时,设置状态将不起作用。我试过你的密码。现在错误没有出现,但是没有调用setState来更新大小。在您的代码中,您调用了newSetState
,但是您似乎需要调用setState
,我更新了我的答案以反映这一点