如何减少抖动中下拉列表的高度

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何减少抖动中下拉列表的高度相关的知识,希望对你有一定的参考价值。

如何减少Flutter中的下拉列表高度。现在它覆盖了全屏。

enter image description here

    import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyAppState();
  }
}

class _MyAppState extends State<MyApp> {
  List<DropdownMenuItem<String>> _dropdownMenuItemsyears;
  String _selectedyear;

  onChangeDropdownItemyear(String selectedYear) {
    setState(() {
      _selectedyear = selectedYear;
    });
  }

  List<String> getYears() {
    List<String> years = new List<String>();
    var date = new DateTime(1900).year;
    var now = new DateTime.now().year;
    int dateFrom = date;
    int dateTo = now;
    for (int i = dateFrom; i <= dateTo; i++) {
      years.add(i.toString());
    }
    years.add("Select");
    return years.reversed.toList();
  }

  List<String> _yearvalue = new List<String>();

  List<DropdownMenuItem<String>> buildDropdownMenuItemsyears(List Years) {
    List<DropdownMenuItem<String>> itemsyears = List();
    for (String Year in Years) {
      itemsyears.add(
        DropdownMenuItem(
          value: Year,
          child: Text(
            Year,
            overflow: TextOverflow.ellipsis,
            style: new TextStyle(
                fontFamily: 'Muli',
                color: Colors.black,
                fontSize: 16,
                decoration: TextDecoration.none),
          ),
        ),
      );
    }
    return itemsyears;
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _yearvalue = getYears();
    _dropdownMenuItemsyears = buildDropdownMenuItemsyears(_yearvalue);
    _selectedyear = _dropdownMenuItemsyears[0].value;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('First app')),
        body: Column(children: [
          Container(
              child: new Container(
            width: 150,
            transform: Matrix4.translationValues(-6, -12, 0),
            child: new Container(
              child: DropdownButtonHideUnderline(
                child: ButtonTheme(
                  alignedDropdown: true,
                  child: DropdownButton(
                    value: _selectedyear,
                    items: _dropdownMenuItemsyears,
                    //Text widgets that have more text and are larger than the hint
                    onChanged: onChangeDropdownItemyear,
                  ),
                ),
              ),
            ),
          )),
        ]),
      ),
    );
  }
}
答案

通过下面链接中提到的DropDownButton类中的可用属性是不可能的。

DropdownButton-class - Flutter Docs

以上是关于如何减少抖动中下拉列表的高度的主要内容,如果未能解决你的问题,请参考以下文章

如何控制select下拉选项的高度

日期选择器如何从下拉列表中选择月份

如何在android中实现下拉刷新?

如何在文本区域标签中的特定光标位置插入选择标签下拉值作为文本片段?

时序分析中时钟抖动是啥 fpga中如何减少时钟抖动

css3 box-sizing: border-box; 引起页面下拉抖动