Closed
flutter/packages
#12863Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
Steps to reproduce
Use SearchAnchor.bar.
Notice how barFocusNode is not a parameter.
Expected results
Let this constructor accept a barFocusNode
Actual results
I can't pipe a FocusNode to this constructor.
Because of this, even tho I submit anything by pressing Enter on my keyboard after seeing some results on the search view, the focus is kept on the search bar. This leads to poor UX if not bugs, directly.
Code sample
Code sample
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
void main() {
runApp(const ProviderScope(child: MyWidget()));
}
class MyWidget extends ConsumerWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
return const MaterialApp(
home: Scaffold(
body: Center(child: MySearchAnchorBar()),
),
);
}
}
class MySearchAnchorBar extends StatefulWidget {
const MySearchAnchorBar({super.key});
@override
State<MySearchAnchorBar> createState() => _MySearchAnchorBarState();
}
class _MySearchAnchorBarState extends State<MySearchAnchorBar> {
late final SearchController _controller;
@override
void initState() {
super.initState();
_controller = SearchController();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return SearchAnchor.bar(
searchController: _controller,
barElevation: WidgetStateProperty.all(2),
barPadding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: 12),
),
viewHeaderTextStyle: const TextStyle(fontSize: 14),
barTextStyle: WidgetStateProperty.all(
const TextStyle(fontSize: 14),
),
viewLeading: const Icon(Icons.search),
viewBarPadding: const EdgeInsets.symmetric(horizontal: 12),
scrollPadding: EdgeInsets.zero,
viewPadding: EdgeInsets.zero,
onSubmitted: (value) {
_controller.closeView(value);
// focus is kept on the bar.
},
suggestionsBuilder: (context, controller) async {
final results = await Future.value(<String>['Example1', 'Example2']);
return [
for (final element in results)
ListTile(
title: Text(
element,
),
onTap: () {
print('Selected: $element');
controller.closeView(element);
},
),
];
},
);
}
}Screenshots or Video
N.A.
Logs
N.A.
Flutter Doctor output
Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.35.5, on macOS 15.6.1 24G90 darwin-arm64, locale en-IT)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 26.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.105.1)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Activity
lucavenir commentedon Oct 23, 2025
I'm more than willing to open a PR for this, it should be trivial.
huycozy commentedon Oct 24, 2025
Hello @lucavenir
When using your sample code, I see another issue (assertion is thrown after pressing Enter key). Also, the focus is lost. Is this intentional or a separate issue?
Demo screenshot/video
Screen.Recording.2025-10-24.at.17.58.01.mov
Output log
About adding a focusNode parameter to
SearchAnchor.bar, I think we can consider this as a feature request.lucavenir commentedon Oct 24, 2025
Yes, thank you, that was the point of this issue. Sorry for the confusion.
Nonetheless, I've updated the above example to make sure no exceptions are thrown.
The above example is to show that:
FocusNodein thereAbout point 1: that is pretty common functionality. You perform some search, you press
Enterhalfway there, and you're happy with the first results. You'd expect the focus not to be on the search bar anymore.lucavenir commentedon Oct 24, 2025
About that - should I make a different issue about the default behavior of the search anchor?
huycozy commentedon Oct 27, 2025
It appears that the default behavior is to lose focus after pressing
Enter, as shown in the demo I shared. This issue may become an applicable proposal if you expect it's able to manage focus onSearchAnchor.bar, by adding afocusNodeparameter to the constructor. Please let me know if that is the case.github-actions commentedon Nov 17, 2025
lucavenir commentedon Nov 17, 2025
dang it, I forgot about this issue.
can we reopen it? there are problems in here.
I took some time to address this, and indeed...
...the behavior I see is completely different.
Again, just to be 110% sure, the code is the following:
code
And to be 220% sure we're on the same page, here's the repro steps:
Example 1andExample 2appearexain the search barEnter(submit)Enteragain_controller.closeView(value)is evaluated again, and that such evaluation leads to acontext.pop)video
Screen.Recording.2025-11-17.at.09.24.54.mov
So, from this issue, I see two different bugs and an enhancement:
onSubmittedevent, focus is not lost.closeViewtwice leads to a.pop(but I'd expect this to trigger anAssertionErrorinstead, or aStateError, or anything else really)SearchAnchor.baraccept afocusNodeparameter (that I can tackle in a PR)Thank you for your patience, @huycozy, if you could confirm or deny any of the above, that'd be great.
huycozy commentedon Nov 17, 2025
welcome back @lucavenir ,
I'm able to reproduce this too. However, per triage pov, I consider it as a bug report type, could you please help to file another issue in bug type, because this issue (based on the title and what is discussed above) seems to a feature request?
Marking this as a feature request.
11 remaining items
flutter-triage-bot commentedon Mar 25, 2026
This issue is assigned to @lucavenir but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!
flutter-triage-bot commentedon Jun 10, 2026
This issue was assigned to @lucavenir but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.
dkwingsmt commentedon Jun 17, 2026
@lucavenir Let's keep it this way to keep the bot happy. We have the PR ready for the new package and that's what matters. :)
lucavenir commentedon Jun 17, 2026
yay! happy bot, happy team! hear you soon!
[material_ui] add a `barFocusNode` to `SearchAnchor.bar` (ref: flutte…
github-actions commentedon Nov 3, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.