Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANR may occur when used with apps that provide document providers #146

Open
masiroyuki opened this issue Oct 2, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@masiroyuki
Copy link

masiroyuki commented Oct 2, 2023

Describe the bug
ANR may occur when accessing applications that provide network folders

To Reproduce

  1. install CIFS Documents Provider to use SMB

  2. Connect to SMB server with CIFS Documents Provider

  3. Open the demo application and get permission to access uri

  4. Turn off wifi (but leave LTE on)

  5. Execute canRead or exists

  6. UI 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):

  • OS: Windows11 pro
  • Browser Edge
  • Version latest

Smartphone (please complete the following information):

  • Device: pixel6a
  • OS: Android13
  • Browser Edge
  • Version latest

Additional context

DemoApp
import 'package:flutter/material.dart';
import 'package:shared_storage/shared_storage.dart' as saf;

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  Uri? selectUri;

  String answer = '';

  void openDocumentTree() => saf.openDocumentTree().then((value) {
    setState(() {
      selectUri = value;
    });
  });

  void canRead(Uri? uri) => saf.canRead(uri ?? Uri()).then((value) {
    setState(() {
      answer = value.toString();
    });
  });

  void exists(Uri? uri) => saf.exists(uri ?? Uri()).then((value) {
    setState(() {
      answer = value.toString();
    });
  });
  

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      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,
            ),
            const SizedBox(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,))
          ],
        ),
      ),
    );
  }
}
@masiroyuki masiroyuki added the bug Something isn't working label Oct 2, 2023
@masiroyuki masiroyuki changed the title With network storage, you can UI becomes unresponsive for a period of time ANR may occur when used with apps that provide document providers Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant