From ffdc5f7a7a21b0ef8a1d37fe99ae7bf2988c26cc Mon Sep 17 00:00:00 2001 From: iamgirya <84345515+iamgirya@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:27:54 +0300 Subject: [PATCH] Fix setState() called during build error Line 'widget.controller.setCurrentPath = snapshot.data!.first.path' Caused an error on open FileManager without controller.setCurrentPath --- lib/file_manager.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/file_manager.dart b/lib/file_manager.dart index 27241d2..5547ea3 100755 --- a/lib/file_manager.dart +++ b/lib/file_manager.dart @@ -230,7 +230,11 @@ class _FileManagerState extends State { if (widget.controller.getCurrentPath.isNotEmpty) { currentDir = Future.value([widget.controller.getCurrentDirectory]); } else { - currentDir = FileManager.getStorageList(); + currentDir = Future(() async { + final list = await FileManager.getStorageList(); + widget.controller.setCurrentPath = list.first.path; + return [widget.controller.getCurrentDirectory]; + }); } } @@ -254,7 +258,6 @@ class _FileManagerState extends State { future: currentDir, builder: (context, snapshot) { if (snapshot.hasData) { - widget.controller.setCurrentPath = snapshot.data!.first.path; return _body(context); } else if (snapshot.hasError) { print(snapshot.error);