import'package:flutter/material.dart';
import'package:shared_storage/shared_storage.dart'as saf;
voidmain() {
runApp(constMyApp());
}
classMyAppextendsStatelessWidget {
constMyApp({super.key});
@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
title:'Flutter Demo',
theme:ThemeData(
colorScheme:ColorScheme.fromSeed(seedColor:Colors.deepPurple),
useMaterial3:true,
),
home:constMyHomePage(title:'Flutter Demo Home Page'),
);
}
}
classMyHomePageextendsStatefulWidget {
constMyHomePage({super.key, requiredthis.title});
finalString title;
@overrideState<MyHomePage> createState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> {
Uri? selectUri;
String answer ='';
voidopenDocumentTree() => saf.openDocumentTree().then((value) {
setState(() {
selectUri = value;
});
});
voidcanRead(Uri? uri) => saf.canRead(uri ??Uri()).then((value) {
setState(() {
answer = value.toString();
});
});
voidexists(Uri? uri) => saf.exists(uri ??Uri()).then((value) {
setState(() {
answer = value.toString();
});
});
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(
backgroundColor:Theme.of(context).colorScheme.inversePrimary,
title:Text(widget.title),
),
body:Center(
child:Column(
mainAxisAlignment:MainAxisAlignment.center,
children:<Widget>[
Text(
'uri: ${selectUri.toString()}',
style:Theme.of(context).textTheme.headlineLarge,
),
Text(
'answer: $answer',
style:Theme.of(context).textTheme.headlineLarge,
),
constSizedBox(height:200,),
FilledButton(
onPressed: () =>openDocumentTree(),
child:Text('openDocumentTree',
style:Theme.of(context).textTheme.bodyMedium,)),
FilledButton(
onPressed: () =>canRead(selectUri),
child:Text('canRead',
style:Theme.of(context).textTheme.bodyMedium,)),
FilledButton(
onPressed: () =>exists(selectUri),
child:Text('exists',
style:Theme.of(context).textTheme.bodyMedium,))
],
),
),
);
}
}
Describe the bug
ANR may occur when accessing applications that provide network folders
To Reproduce
install CIFS Documents Provider to use SMB
Connect to SMB server with CIFS Documents Provider
Open the demo application and get permission to access uri
Turn off wifi (but leave LTE on)
Execute
canReadorexistsUI freezes and ANR occurs
Expected behavior
By separating threads in a coroutine
Prevents the UI from freezing
Screenshots
demomp4.mp4
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
DemoApp