[Breaking Change] Introduce four required getter methods to TextSelectionDelegate

58 views
Skip to first unread message

Chun-Heng Tai

unread,
May 22, 2019, 12:43:43 PM5/22/19
to flutter-...@googlegroups.com

If you are not implementing the abstract class TextSelectionDelegate or class EditableTextState, this will not affect you.

Summary


We would like to introduce four required getter methods to the abstract class TextSelectionDelegate. The four getter methods are cutEnabled, copyEnabled, pasteEnabled, selectAllEnabled.


The proposed idea is that any class implementing this abstract class using the ‘with’ keyword will also need to implement these four getter methods.


Justification


Currently, the selection context menu shows cut, copy, paste, and selectAll options based on the state of the text. This is not sufficient when we introduce a read-only text field. We would like to have explicit control over which options are disabled or enabled.


Related Issues


https://github.com/flutter/flutter/issues/14014

https://github.com/flutter/flutter/issues/5422


How to migrate


If you have a State class that implements TextSelectionDelegate, you can fix it by implementing the four getter methods


class CustomWidgetState extends State<CustomWidget> implements TextSelectionDelegate {

   // …..

   // ……


   // Add the following four getter methods.

   @override

   bool get cutEnabled {

       // Customized logic if you want to conditionally turn off cut.

       return true

   }


   @override

   bool get copyEnabled {

       // Customized logic if you want to conditionally turn off copy.

       return true

   }


   @override

   bool get pasteEnabled {

       // Customized logic if you want to conditionally turn off paste.

       return true

   }


   @override

   bool get selectAllEnabled {

       // Customized logic if you want to conditionally turn off selectAll.

       return true

   }


}


Please reach out if this change would be a problem for you. You can reply to https://github.com/flutter/flutter/issues/14014.


Cheers,

Chun-Heng


Chun-Heng Tai

unread,
May 22, 2019, 1:37:51 PM5/22/19
to Flutter Announcements (flutter-announce)

One minor correction.

In the summary,   'The proposed idea is that any class implementing this abstract class using the ‘implements’ keyword will also need to implement these four getter methods.'
Reply all
Reply to author
Forward
0 new messages