@@ -5776,6 +5776,125 @@ void main() {
57765776 expect (state.currentTextEditingValue.text, '12345' );
57775777 expect (state.currentTextEditingValue.composing, TextRange .empty);
57785778 });
5779+
5780+ group ('callback errors' , () {
5781+ const String errorText = 'Test EditableText callback error' ;
5782+
5783+ testWidgets ('onSelectionChanged can throw errors' , (WidgetTester tester) async {
5784+ await tester.pumpWidget (MaterialApp (
5785+ home: EditableText (
5786+ showSelectionHandles: true ,
5787+ maxLines: 2 ,
5788+ controller: TextEditingController (
5789+ text: 'flutter is the best!' ,
5790+ ),
5791+ focusNode: FocusNode (),
5792+ cursorColor: Colors .red,
5793+ backgroundCursorColor: Colors .blue,
5794+ style: Typography .material2018 (platform: TargetPlatform .android).black.subtitle1.copyWith (fontFamily: 'Roboto' ),
5795+ keyboardType: TextInputType .text,
5796+ selectionControls: materialTextSelectionControls,
5797+ onSelectionChanged: (TextSelection selection, SelectionChangedCause cause) {
5798+ throw FlutterError (errorText);
5799+ },
5800+ ),
5801+ ));
5802+
5803+ // Interact with the field to establish the input connection.
5804+ await tester.tap (find.byType (EditableText ));
5805+ final dynamic error = tester.takeException ();
5806+ expect (error, isFlutterError);
5807+ expect (error.toString (), contains (errorText));
5808+ });
5809+
5810+ testWidgets ('onChanged can throw errors' , (WidgetTester tester) async {
5811+ await tester.pumpWidget (MaterialApp (
5812+ home: EditableText (
5813+ showSelectionHandles: true ,
5814+ maxLines: 2 ,
5815+ controller: TextEditingController (
5816+ text: 'flutter is the best!' ,
5817+ ),
5818+ focusNode: FocusNode (),
5819+ cursorColor: Colors .red,
5820+ backgroundCursorColor: Colors .blue,
5821+ style: Typography .material2018 (platform: TargetPlatform .android).black.subtitle1.copyWith (fontFamily: 'Roboto' ),
5822+ keyboardType: TextInputType .text,
5823+ onChanged: (String text) {
5824+ throw FlutterError (errorText);
5825+ },
5826+ ),
5827+ ));
5828+
5829+ // Modify the text and expect an error from onChanged.
5830+ await tester.enterText (find.byType (EditableText ), '...' );
5831+ final dynamic error = tester.takeException ();
5832+ expect (error, isFlutterError);
5833+ expect (error.toString (), contains (errorText));
5834+ });
5835+
5836+ testWidgets ('onEditingComplete can throw errors' , (WidgetTester tester) async {
5837+ await tester.pumpWidget (MaterialApp (
5838+ home: EditableText (
5839+ showSelectionHandles: true ,
5840+ maxLines: 2 ,
5841+ controller: TextEditingController (
5842+ text: 'flutter is the best!' ,
5843+ ),
5844+ focusNode: FocusNode (),
5845+ cursorColor: Colors .red,
5846+ backgroundCursorColor: Colors .blue,
5847+ style: Typography .material2018 (platform: TargetPlatform .android).black.subtitle1.copyWith (fontFamily: 'Roboto' ),
5848+ keyboardType: TextInputType .text,
5849+ onEditingComplete: () {
5850+ throw FlutterError (errorText);
5851+ },
5852+ ),
5853+ ));
5854+
5855+ // Interact with the field to establish the input connection.
5856+ final Offset topLeft = tester.getTopLeft (find.byType (EditableText ));
5857+ await tester.tapAt (topLeft + const Offset (0.0 , 5.0 ));
5858+ await tester.pump ();
5859+
5860+ // Submit and expect an error from onEditingComplete.
5861+ await tester.testTextInput.receiveAction (TextInputAction .done);
5862+ final dynamic error = tester.takeException ();
5863+ expect (error, isFlutterError);
5864+ expect (error.toString (), contains (errorText));
5865+ });
5866+
5867+ testWidgets ('onSubmitted can throw errors' , (WidgetTester tester) async {
5868+ await tester.pumpWidget (MaterialApp (
5869+ home: EditableText (
5870+ showSelectionHandles: true ,
5871+ maxLines: 2 ,
5872+ controller: TextEditingController (
5873+ text: 'flutter is the best!' ,
5874+ ),
5875+ focusNode: FocusNode (),
5876+ cursorColor: Colors .red,
5877+ backgroundCursorColor: Colors .blue,
5878+ style: Typography .material2018 (platform: TargetPlatform .android).black.subtitle1.copyWith (fontFamily: 'Roboto' ),
5879+ keyboardType: TextInputType .text,
5880+ onSubmitted: (String text) {
5881+ throw FlutterError (errorText);
5882+ },
5883+ ),
5884+ ));
5885+
5886+ // Interact with the field to establish the input connection.
5887+ final Offset topLeft = tester.getTopLeft (find.byType (EditableText ));
5888+ await tester.tapAt (topLeft + const Offset (0.0 , 5.0 ));
5889+ await tester.pump ();
5890+
5891+ // Submit and expect an error from onSubmitted.
5892+ await tester.testTextInput.receiveAction (TextInputAction .done);
5893+ final dynamic error = tester.takeException ();
5894+ expect (error, isFlutterError);
5895+ expect (error.toString (), contains (errorText));
5896+ });
5897+ });
57795898}
57805899
57815900class MockTextFormatter extends TextInputFormatter {
0 commit comments