Skip to content

SearchAnchor.bar lacks a focusNode parameter #177454

@lucavenir

Description

@lucavenir

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 projectc: new featureNothing broken; request for a new capabilityf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions