颤振:下拉按钮的弹出位置不正确



我的下拉按钮的弹出位置不正确。我不知道是什么导致了这个问题,弹出窗口在按钮的右侧移动,这在一定程度上与Row小部件和生成器有关。我在master分支上。请在此处查看示例代码DartPad样品

import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
builder: (context, child) => Scaffold(
body: Row(
children: [
Container(
width: 200,
color: Colors.blue,
child: Column(children: [
Text("Side Menu"),
])
),
Expanded(child: child),
],
),
),
initialRoute: "/",
onGenerateRoute: (_) => MaterialPageRoute(
builder: (BuildContext context) => Center(
child: DropdownButton(
hint: Text("test"),
value: 0,
items: [
DropdownMenuItem(child: Text("test 1"), value: 0),
DropdownMenuItem(child: Text("test 2"), value: 1),
DropdownMenuItem(child: Text("test 3"), value: 2),
],
onChanged: (value) {},
),
),
),
);
}
}

试着实现这个代码,它肯定会起作用祝你好运:(

import 'package:flutter/material.dart';
void main() => runApp(MyApp());
/// This Widget is the main application widget.
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: 24,
elevation: 16,
style: TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['One', 'Two', 'three', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
);
}
}

最新更新