Skip to content

[DropdownButton]: alignment parameter doesn't work for hint when isExpanded: true  #102751

@TahaTesser

Description

@TahaTesser

https://master-api.flutter.dev/flutter/material/DropdownButton/alignment.html

Defines how the hint or the selected item is positioned within the button.
This property must not be null. It defaults to AlignmentDirectional.centerStart.

Description

DropdownButton.alignment should align hint when isExpanded is false or true.

minimal code sample
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flutter code sample for DropdownButton.selectedItemBuilder

import 'package:flutter/material.dart';

Map<String, String> cities = <String, String>{
  'New York': 'NYC',
  'Los Angeles': 'LA',
  'San Francisco': 'SF',
  'Chicago': 'CH',
  'Miami': 'MI',
};

void main() => runApp(const DropdownButtonApp());

class DropdownButtonApp extends StatelessWidget {
  const DropdownButtonApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('DropdownButton Sample')),
        body: const Center(child: DropdownButtonExample()),
      ),
    );
  }
}

class DropdownButtonExample extends StatefulWidget {
  const DropdownButtonExample({Key? key}) : super(key: key);

  @override
  State<DropdownButtonExample> createState() => _DropdownButtonExampleState();
}

class _DropdownButtonExampleState extends State<DropdownButtonExample> {
  String? selectedItem;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          DropdownButton<String>(
            value: selectedItem,
            alignment: Alignment.centerRight,
            hint: const Text('Hint'),
            onChanged: (String? string) {
              // This is called when the user selects an item.
              setState(() => selectedItem = string);
            },
            items: cities.keys.map<DropdownMenuItem<String>>((String item) {
              return DropdownMenuItem<String>(
                value: item,
                child: Text(item),
              );
            }).toList(),
          ),
          const SizedBox(height: 20),
          DropdownButton<String>(
            value: selectedItem,
            isExpanded: true,
            alignment: Alignment.centerRight,
            hint: const Text('Hint'),
            onChanged: (String? string) {
              // This is called when the user selects an item.
              setState(() => selectedItem = string);
            },
            items: cities.keys.map<DropdownMenuItem<String>>((String item) {
              return DropdownMenuItem<String>(
                value: item,
                child: Text(item),
              );
            }).toList(),
          ),
        ],
      ),
    );
  }
}

Actual Results

Screenshot 2022-04-28 at 14 16 19

Expected Results

Screenshot 2022-04-28 at 14 16 30

Metadata

Metadata

Assignees

Labels

f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions