Text Selection causes a pop to be invoked.

Background:

When making a text selection, and selecting any option or tapping out of the option box to dismiss it, the navigation scope is popped, and then doesn't actually pop anything.

Expected behavior: 

No pop should be invoked at all.


Why is this an issue:
My code saves to a database that is listened to upon scope pop. When the scope is popped in this case, it saves to the database and then the listener reloads the page giving an unpleasant experience.


Video demonstration:

https://youtu.be/0VQACkKi2pU


Minimally reproducible code snippet:

```

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';


void main() => runApp(const MaterialApp(title: 'PDF Viewer App', home: HomePage()));


class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('PDF Viewer App')),
      body: Center(
        child: ElevatedButton(
          child: const Text('Open PDF'),
          onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (context) => const PDFViewerPage())),
        ),
      ),
    );
  }
}


class PDFViewerPage extends StatelessWidget {
  const PDFViewerPage({Key? key}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: true,
      onPopInvoked: (didPop) async {
        ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('PDF Viewer Closing')));
      },
      child: Scaffold(
        appBar: AppBar(title: const Text('PDF Viewer')),
        body: SfPdfViewer.asset('assets/private_flood_status.pdf'),
      ),
    );
  }
}

```


3 Replies

IP ImmanKumarP Palanikumar Syncfusion Team August 6, 2024 11:19 AM UTC

Hi Jeremy,


In SfPdfViewer, we have a feature that allows clearing the text selection using the device's back button when the application is deployed on mobile devices. To enable this feature, we are adding a LocalHistoryEntry to the ModalRoute using the addLocalHistoryEntry method. Also, on clearing the text selection this LocalHistoryEntry  is removed from the ModalRoute and due to this the onPopInvoked callback is triggered.


Please confirm if we should share a workaround to differentiate between when the text selection is cleared and when the navigation is popped.


Regards,
Imman Kumar P



JI Jeremy Isenburg replied to ImmanKumarP Palanikumar August 6, 2024 03:53 PM UTC

Hi Imman,


Could this be added as a flag we can enable in the viewer constructor? Some devices don't have a back button, like the iPhone.

A workaround may be useful to me if this can't be changed.

Thanks,



IP ImmanKumarP Palanikumar Syncfusion Team August 7, 2024 11:23 AM UTC

Hi Jeremy,

The reported issue seems to be fixed in the latest Flutter SDK 3.24.

Could you please update the Flutter SDK and confirm us whether the issue resolved?

We have atached the sample and video recording for your reference.

Regards,
Imman Kumar P



Attachment: F192731_c5227cdc.zip

Loader.
Up arrow icon