Flutter App 使用大量 RAM 内存,几乎 1GB

问题描述

我正在尝试构建一个应用程序,该应用程序可显示内部存储中的 .txt 文件、.png 文件和 .aac 文件,例如聊天屏幕。首先显示大量图像对我来说是一团糟。我可以通过对图像使用 cacheWidth 和 cacheHeight 来减少内存压力。但是我意识到在使用 release apk 时,Ram 内存使用量随着时间的推移而增加,直到接近 1GB,而且使用量很大。希望得到您的帮助以减少此问题。导航到另一个页面时尝试删除缓存目录是否发生缓存问题。

 Future<void> _deleteCacheDir() async {
final cacheDir = await getTemporaryDirectory();
if (cacheDir.existsSync()) {
  cacheDir.deleteSync(recursive: true);
}

}

显示所有文件的列表视图;

Expanded(
              child: SingleChildScrollView(
                reverse: true,child: new Column(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,children: <Widget>[
                        ListView.separated (
                          shrinkWrap: true,physics: NeverScrollableScrollPhysics(),itemCount: fileList.length,separatorBuilder: (context,i) {

我如何在列表视图中显示图像;

           return Slidable(
                                actionPane: SlidableDrawerActionPane(),direction: Axis.horizontal,actionExtentRatio: 0.25,child: Column  (
                                    crossAxisAlignment: CrossAxisAlignment.start,children: [
                                      Padding(
                                        padding: const EdgeInsets.fromLTRB(8,3,3),child: Container(

                                          child: GestureDetector(
                                            onTap: (){
                                              if (_currentStatus == RecordingStatus.Recording || _currentStatus == RecordingStatus.Paused )
                                              {
                                                _currentStatus = RecordingStatus.Stopped;
                                                _recording.stop();
                                              }
                                              audplayer.dispose();
                                              _deleteCacheDir();
                                              Navigator.push(
                                                  context,MaterialPageRoute(
                                                    builder: (context) => showRecorderPhoto(pathtxt: widget.pathtxt,pathpng: imgpth,hangisayfa: widget.hangisayfa,),));

                                              },child: Card(
                                                //semanticContainer: true,clipBehavior: Clip.antiAliasWithSaveLayer,shape: RoundedRectangleBorder(
                                                  borderRadius: BorderRadius.circular(15.0),elevation: 5,margin: EdgeInsets.all(1),child:
                                                    
                                                    // Image showing lines
                                                Image.file(file,fit: BoxFit.fill,width: screenWidth/2.3,height: screenHeight/2.3,cacheWidth: width2.toInt(),cacheHeight: height2.toInt(),filterQuality: FilterQuality.high,)
                                            ),)
                                    ]
                                ),secondaryActions: <Widget>[
                                  new IconSlideAction(
                                    caption: '',color: color,icon: Icons.share,onTap: (){
                                      //Share.share(imgpth);
                                      Share.shareFiles([imgpth],text: '.',subject: "Fil");
                                    },new IconSlideAction(
                                    caption: 'Delete',icon: Icons.delete,onTap: (){
                                      fileList.remove(fileList[i]);
                                      final dir = io.Directory(imgpth);
                                      dir.deleteSync(recursive:true);
                                      listYazar();
                                    },],);

我如何显示txt文件

   child: Padding(
                                      padding: const EdgeInsets.only(left:8,right:8,bottom:3,top:3 ),child: Row(
                                        children: [
                                          Flexible(
                                            child: ConstrainedBox(
                                              constraints: new BoxConstraints(minHeight: 20,minWidth: 10),child: DecoratedBox(
                                                decoration: Boxdecoration(
                                                  borderRadius: BorderRadius.circular(10),color: Colors.white,child: Padding(
                                                  padding: const EdgeInsets.all(15),child:
                                                          txtList[x].toString().contains("b")   ?  Text(notList[x],style: TextStyle(
                                                              fontWeight: FontWeight.bold,fontFamily: "Gothic",color: Colors.blue),)
                                                              : Text(notList[x],style: TextStyle(fontFamily: "Gothic",)),

请大家帮帮忙!!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)