Skip to content

SearchBar does not align text vertically #127092

@anlumo

Description

@anlumo

Is there an existing issue for this?

Steps to reproduce

  1. Add a SearchBar widget
  2. Make its height 40 points, which is less than the default (via constraints: const BoxConstraints(minHeight: 40, maxHeight: 40))

Expected results

Nicely looking search field with everything centered vertically.

Screenshots from my actual application:

This is how it looks with the default height of 56, which is what I would expect:
image

Actual results

image

Note how the icon is positioned correctly. It's just the text.

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'SearchBar Bug',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: Scaffold(
        appBar: AppBar(
            flexibleSpace: const SearchBar(
          leading: Icon(Icons.search, size: 20),
          hintText: 'Search',
          constraints: BoxConstraints(minHeight: 40, maxHeight: 40),
        )),
      ),
    );
  }
}

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.0, on Microsoft Windows [Version 10.0.19045.2965], locale en-AT)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Chrome - develop for the web
[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.26)
[!] Android Studio (not installed)
[✓] VS Code (version 1.78.2)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

Labels

a: text inputEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.found in release: 3.10Found to occur in 3.10found in release: 3.11Found to occur in 3.11frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions