From a1d02b657ef99726a55f6cc77e6fbe9813f89162 Mon Sep 17 00:00:00 2001 From: Kishan Rathore <34465683+rkishan516@users.noreply.github.com> Date: Thu, 23 Jan 2025 01:05:55 +0530 Subject: [PATCH] fix: Add enabled property for search anchor named constructor (#161468) fix: Add enabled property for search anchor named constructor Fixes: #161063 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com> --- .../lib/src/material/search_anchor.dart | 2 ++ .../test/material/search_anchor_test.dart | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/flutter/lib/src/material/search_anchor.dart b/packages/flutter/lib/src/material/search_anchor.dart index f5f8a43e28..5c74607cfa 100644 --- a/packages/flutter/lib/src/material/search_anchor.dart +++ b/packages/flutter/lib/src/material/search_anchor.dart @@ -204,6 +204,7 @@ class SearchAnchor extends StatefulWidget { TextInputType? keyboardType, EdgeInsets scrollPadding, EditableTextContextMenuBuilder contextMenuBuilder, + bool enabled, }) = _SearchAnchorWithSearchBar; /// Whether the search view grows to fill the entire screen when the @@ -1187,6 +1188,7 @@ class _SearchAnchorWithSearchBar extends SearchAnchor { super.keyboardType, EdgeInsets scrollPadding = const EdgeInsets.all(20.0), EditableTextContextMenuBuilder contextMenuBuilder = SearchBar._defaultContextMenuBuilder, + super.enabled, }) : super( viewHintText: viewHintText ?? barHintText, headerHeight: viewHeaderHeight, diff --git a/packages/flutter/test/material/search_anchor_test.dart b/packages/flutter/test/material/search_anchor_test.dart index 9b6ad0e263..a36461d85b 100644 --- a/packages/flutter/test/material/search_anchor_test.dart +++ b/packages/flutter/test/material/search_anchor_test.dart @@ -3200,6 +3200,33 @@ void main() { expect(controller.value.text, initValue); }); + testWidgets('Block entering text on disabled widget with SearchAnchor.bar', ( + WidgetTester tester, + ) async { + const String initValue = 'init'; + final TextEditingController controller = TextEditingController(text: initValue); + addTearDown(controller.dispose); + + await tester.pumpWidget( + MaterialApp( + home: Material( + child: Center( + child: SearchAnchor.bar( + suggestionsBuilder: (BuildContext context, SearchController controller) { + return []; + }, + enabled: false, + ), + ), + ), + ), + ); + + const String testValue = 'abcdefghi'; + await tester.enterText(find.byType(SearchBar), testValue); + expect(controller.value.text, initValue); + }); + testWidgets('Disabled SearchBar semantics node still contains value', ( WidgetTester tester, ) async {