Flutter DropdownButton 中可能出现渲染错误
Possible render error in Flutter DropdownButton
我正在 Flutter Web 上开发 Spotify UI 克隆(网络版),并实现了带有 back/forward 按钮的顶部栏和右侧的用户内容,如一个专栏,但他们意识到该栏固定在它的位置上,并且您的音乐建议会在其中滚动。
我的解决方案是设置一个 Stack,栏在顶部,如下所示:
_mainScreen(BuildContext context){
Size size = MediaQuery.of(context).size;
return Container(
padding: EdgeInsets.symmetric(horizontal: 15.0),
color: Color.fromRGBO(22, 22, 22, 1.0),
height: double.infinity,
width: size.width*0.82,
child: Stack(
children: <Widget>[
SingleChildScrollView(
child: Column(
children: <Widget>[
SizedBox(height: size.height*0.09,),
_suggestionLists(size)
],
),
),
_topBar(size)
],
)
);
}
然后事情发生了:
That white line isn't supposed to be there
在进行我之前提到的更改之前,它也不存在。
这是该小部件的代码:
_profileButtons(Size size){
return Container(
height: size.height*0.05,
padding: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(
color: Color.fromRGBO(15, 15, 15, 0.8),
borderRadius: BorderRadius.circular(100.0)
),
child: DropdownButton<String>(
dropdownColor: Color.fromRGBO(75, 75, 75, 1.0),
style: TextStyle(color: Colors.white),
hint: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(1.0),
child: Icon(Icons.person, color: Colors.white, size: 20,),
decoration: BoxDecoration(
color: Color.fromRGBO(75, 75, 75, 1.0),
border: Border.all(color: Color.fromRGBO(75, 75, 75, 1.0)),
borderRadius: BorderRadius.circular(100.0)
),
),
SizedBox(width: 5.0,),
Text('Your UserName', style: TextStyle(color: Colors.white),),
],
),
icon: Icon(Icons.arrow_drop_down, color: Colors.white,),
items: <String>['Account', 'Profile', 'Log out'].map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {},
)
);
}
我试过在容器、边框等方面搞乱一些,但我似乎没有发现它有什么问题,会不会是渲染错误?
如果需要,我会提供额外的 code/details
您可以复制粘贴 运行 下面的完整代码
要隐藏下划线,可以使用 DropdownButtonHideUnderline
wrap DropdownButton
代码片段
DropdownButtonHideUnderline(
child: DropdownButton<String>(
工作演示
完整代码
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
_profileButtons(Size size) {
return Container(
height: size.height * 0.05,
padding: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(
color: Color.fromRGBO(15, 15, 15, 0.8),
borderRadius: BorderRadius.circular(100.0)),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
dropdownColor: Color.fromRGBO(75, 75, 75, 1.0),
style: TextStyle(color: Colors.white),
hint: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(1.0),
child: Icon(
Icons.person,
color: Colors.white,
size: 20,
),
decoration: BoxDecoration(
color: Color.fromRGBO(75, 75, 75, 1.0),
border:
Border.all(color: Color.fromRGBO(75, 75, 75, 1.0)),
borderRadius: BorderRadius.circular(100.0)),
),
SizedBox(
width: 5.0,
),
Text(
'Your UserName',
style: TextStyle(color: Colors.white),
),
],
),
icon: Icon(
Icons.arrow_drop_down,
color: Colors.white,
),
items:
<String>['Account', 'Profile', 'Log out'].map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {},
),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(appBar: AppBar(), body: _profileButtons(Size(800, 800)));
}
}
我正在 Flutter Web 上开发 Spotify UI 克隆(网络版),并实现了带有 back/forward 按钮的顶部栏和右侧的用户内容,如一个专栏,但他们意识到该栏固定在它的位置上,并且您的音乐建议会在其中滚动。
我的解决方案是设置一个 Stack,栏在顶部,如下所示:
_mainScreen(BuildContext context){
Size size = MediaQuery.of(context).size;
return Container(
padding: EdgeInsets.symmetric(horizontal: 15.0),
color: Color.fromRGBO(22, 22, 22, 1.0),
height: double.infinity,
width: size.width*0.82,
child: Stack(
children: <Widget>[
SingleChildScrollView(
child: Column(
children: <Widget>[
SizedBox(height: size.height*0.09,),
_suggestionLists(size)
],
),
),
_topBar(size)
],
)
);
}
然后事情发生了: That white line isn't supposed to be there
在进行我之前提到的更改之前,它也不存在。 这是该小部件的代码:
_profileButtons(Size size){
return Container(
height: size.height*0.05,
padding: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(
color: Color.fromRGBO(15, 15, 15, 0.8),
borderRadius: BorderRadius.circular(100.0)
),
child: DropdownButton<String>(
dropdownColor: Color.fromRGBO(75, 75, 75, 1.0),
style: TextStyle(color: Colors.white),
hint: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(1.0),
child: Icon(Icons.person, color: Colors.white, size: 20,),
decoration: BoxDecoration(
color: Color.fromRGBO(75, 75, 75, 1.0),
border: Border.all(color: Color.fromRGBO(75, 75, 75, 1.0)),
borderRadius: BorderRadius.circular(100.0)
),
),
SizedBox(width: 5.0,),
Text('Your UserName', style: TextStyle(color: Colors.white),),
],
),
icon: Icon(Icons.arrow_drop_down, color: Colors.white,),
items: <String>['Account', 'Profile', 'Log out'].map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {},
)
);
}
我试过在容器、边框等方面搞乱一些,但我似乎没有发现它有什么问题,会不会是渲染错误? 如果需要,我会提供额外的 code/details
您可以复制粘贴 运行 下面的完整代码
要隐藏下划线,可以使用 DropdownButtonHideUnderline
wrap DropdownButton
代码片段
DropdownButtonHideUnderline(
child: DropdownButton<String>(
工作演示
完整代码
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
_profileButtons(Size size) {
return Container(
height: size.height * 0.05,
padding: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(
color: Color.fromRGBO(15, 15, 15, 0.8),
borderRadius: BorderRadius.circular(100.0)),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
dropdownColor: Color.fromRGBO(75, 75, 75, 1.0),
style: TextStyle(color: Colors.white),
hint: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(1.0),
child: Icon(
Icons.person,
color: Colors.white,
size: 20,
),
decoration: BoxDecoration(
color: Color.fromRGBO(75, 75, 75, 1.0),
border:
Border.all(color: Color.fromRGBO(75, 75, 75, 1.0)),
borderRadius: BorderRadius.circular(100.0)),
),
SizedBox(
width: 5.0,
),
Text(
'Your UserName',
style: TextStyle(color: Colors.white),
),
],
),
icon: Icon(
Icons.arrow_drop_down,
color: Colors.white,
),
items:
<String>['Account', 'Profile', 'Log out'].map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (_) {},
),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(appBar: AppBar(), body: _profileButtons(Size(800, 800)));
}
}