1

I'm showing content with bottomsheet, i'm updating folder size after calculating it, using statefulbuilder's setState, i used mounted condition also, then also it showing setState after called dispose, Help me to solve this.

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,
                ),
              ],
            ),
          );
        });
      });
Christopher Moore
  • 15,626
  • 10
  • 42
  • 52
MSARKrish
  • 3,355
  • 4
  • 30
  • 43

1 Answers1

0

try the following

if (!mounted){
    setState(() {
        size = value;
    }),
};
ByteMe
  • 1,575
  • 1
  • 12
  • 23
  • if i use above condition, then setState will not work when bottomsheet is open. I tried your code. now error not came, but setState not called to update the size. – MSARKrish Sep 10 '20 at 05:28
  • in your code, you called `newSetState` however it seems you need to call `setState`, I've updated my answer to reflect this – ByteMe Sep 10 '20 at 11:25