-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Closed
Copy link
Labels
f: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
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
Expected Results
Metadata
Metadata
Assignees
Labels
f: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Type
Projects
Status
Done (PR merged)

