每当我尝试在 a 、 或 a 中设置CupertinoPicker
aModalBottomSheet
时Column
,Row
它Container
似乎占据了尽可能多的位置。
无论如何将 的大小/高度限制ModalBottomSheet
为 的实际大小CupertinoPicker
,这显然比高度小得多ModalBottomSheet
(通过其灰色背景颜色变得明显)。
这是我的代码:
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(body:
Center(child: RaisedButton(onPressed: () => showPicker(context),
child: Text('Show Bottom Sheet')),)
);
}
Widget showPicker(BuildContext context) {
showModalBottomSheet(
context: context,
builder: (context) {
return Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('This is a picker'),
Expanded(
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: Container(
height: 100,
child: CupertinoPicker(
itemExtent: 30,
onSelectedItemChanged: (int index) {
print(index);
},
children: <Widget>[
Center(child: Text("Item 1")),
Center(child: Text("Item 2")),
Center(child: Text("Item 3")),
],
),
),
),
],
),
),
],
),
);
});
}
}
这就是我得到的:
感谢您提供任何提示、提示和建议!