dart - 回复 : create a dropdown button in flutter

我在构建中使用了 DropDownButton,但我希望箭头显示在末尾,下拉项目从箭头显示,但在我的应用程序中它们从顶部显示。我已附上截图供您引用。

请告诉我如何更改此设置,或者是否有任何其他方法可以简单地创建一个下拉菜单。

一个例子将不胜感激。

请原谅我的代码,因为我是编程新手,欢迎提出任何意见或建议。

非常感谢, 鲯鳅。

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'dart:ui';

void main(){
    runApp(new BranchSetup());
      }
      
class BranchSetup extends StatefulWidget {
    @override
    State<StatefulWidget> createState() {
         return new _BranchSetupState();
          }
       } 

    class _BranchSetupState extends State<BranchSetup> with 
                                WidgetsBindingObserver {

     @override
           Widget build(BuildContext context){
           return new MaterialApp(
              theme: new ThemeData(
                  primaryColor: const Color(0xFF229E9C),
                                ),
              title: 'Branch Setup',
              home: new Scaffold(
              body: new Container(
              child: new ListView(
                children: <Widget>[
                 new Container(
                   margin: const EdgeInsets.all(16.0),
                    child: new Row(
                     children: <Widget>[
                      new Expanded(
                        child: new TextFormField(
            decoration: new InputDecoration(                          
                       labelText: 'Branch Name',
                   ),
                ),
              ),
            ],
          ),
         ),
          new Container(
            margin: const EdgeInsets.all(16.0),
            child:
              new DropdownButton<String>(
                items: <String>['Mens','Womans']
                      .map((String value) {
                    return new DropdownMenuItem<String>(
                        value: value,
                        child: new Text(value),
                    );
                  }
                  ).toList(),
               onChanged: null,
                ),
            ),

          ],
        ),
        ),
     ),
    );
   }

  }

最佳答案

这看起来像是 Flutter 中的一个错误。我提交了 issue .

与此同时,您可以通过将 DropdownButton 包装在 Column 中来解决此问题。

import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(home: new DemoApp()));
}

class DemoApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(title: new Text('DropdownButton Example')),
      body: new ListView(
        children: [
          new Column(
            children: <Widget>[
              new DropdownButton<String>(
                items: <String>['Foo', 'Bar'].map((String value) {
                  return new DropdownMenuItem<String>(
                    value: value,
                    child: new Text(value),
                  );
                }).toList(),
                onChanged: (_) {},
              ),
            ],
          ),
        ],
      ),
    );
  }
}

https://stackoverflow.com/questions/46169682/

相关文章:

flutter - 如何在等待来自后端 API 的数据时最初显示 RefreshIndicator?

dart - Flutter 删除目录文件

dart - 如何检查 Flutter Text 小部件是否溢出

android - 如何从 Flutter App 连接 Ms SQL?

dart - Flutter:使用 SlideTransition

dart - Flutter:如何获取文本行数

dart - 在 flutter 中使用底部导航栏在页面之间传递数据

flutter - 具有水平、未填充子项的 PageView

dart - 在小部件树中使用 const 会提高性能吗?

android-studio - flutter Android Studio : Error re