如何在flutter中调整下拉列表的高度和宽度(我已经给出了代码,告诉我如何调整即可)

f2uvfpb9  于 2023-02-25  发布在  Flutter
关注(0)|答案(2)|浏览(174)
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

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

class MyStatefulWidget extends StatefulWidget {
  MyStatefulWidget({Key key}) : super(key: key);

  @override
  _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  String dropdownValue = 'One';

  @override
  Widget build(BuildContext context) {
    return DropdownButton<String>(
      value: dropdownValue,
      icon: Icon(Icons.arrow_downward),
      iconSize: 15,
      elevation: 16,
      style: TextStyle(color: Colors.deepPurple),
      underline: Container(
        height: 2,
        color: Colors.deepPurpleAccent,
      ),
      onChanged: (String newValue) {
        setState(() {
          dropdownValue = newValue;
        });
      },
      items: <String>['One', 'Two', 'Free', 'Four']
          .map<DropdownMenuItem<String>>((String value) {
        return DropdownMenuItem<String>(
          value: value,
          child: Text(value),
        );
      }).toList(),
    );
  }
}
ncecgwcz

ncecgwcz1#

您可以在下拉列表中添加width: (specification)height: (specification)
请使用“代码示例”格式选项。

2ul0zpep

2ul0zpep2#

你可以这样做:

return Container(
  child: DropdownButton(
    value: dropdownValue,
    icon: Icon(Icons.arrow_downward), 
    iconSize: 15, 
    elevation: 16, 
    style: TextStyle(color: Colors.deepPurple), 
    underline: Container( 
      height: 2, 
      color: Colors.deepPurpleAccent, 
    ), 
    onChanged: (newValue) {
      setState(() { 
        dropdownValue = newValue; 
      });
    }, 
    items: ['One', 'Two', 'Free', 'Four'] .map<DropdownMenuItem>((String value) { 
      return DropdownMenuItem(
        value: value,
        child: Container(
          height: 100,
          width: 200,
          alignment: Alignment.centerLeft,
          child: Text(value)
        )
      ); 
    }).toList(),
  )
);

顺便说一句,请使用代码示例格式选项。

相关问题