[英]CupertinoDatePicker A RenderFlex overflowed by Infinity pixels on the bottom
我嘗試在容器內的 CupertinoDatePicker 上方添加一排取消和完成按鈕,但是遇到錯誤,go 可能出現什么錯誤?
════════ 渲染庫捕獲的異常══════════════════════════════════════Render溢出底部無限像素。 相關的導致錯誤的小部件是 Column
String _selectedDueDate;
var formatter = new DateFormat('dd-MM-yyyy');
ListTile(
leading: const Icon(Icons.today),
title: const Text('Due Date*'),
subtitle: _selectedDueDate
onTap: () {
showCupertinoModalPopup(
context: context,
builder: (context) {
return Container(
color: Colors.white,
height: 300.0,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.zero),
child: Text(
"Cancel",
),
onPressed: () => {},
),
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.zero),
child: Text(
"Done",
),
onPressed: () => {},
),
],
),
CupertinoDatePicker(
initialDateTime:
DateTime.now().add(new Duration(days: 7)),
minimumDate: DateTime.now(),
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (date) {
setState(() {
print(date);
_selectedDueDate = formatter.format(date);
});
},
),
],
),
);
});
},
),
您可以在下面復制粘貼運行完整代碼
你可以用Flexible
包裹CupertinoDatePicker
代碼片段
Flexible(
child: CupertinoDatePicker(
工作演示
完整代碼
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _selectedDueDate;
var formatter = new DateFormat('dd-MM-yyyy');
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListTile(
leading: const Icon(Icons.today),
title: const Text('Due Date*'),
subtitle: Text("$_selectedDueDate"),
onTap: () {
showCupertinoModalPopup(
context: context,
builder: (context) {
return Container(
color: Colors.white,
height: 300.0,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.zero),
child: Text(
"Cancel",
),
onPressed: () => {},
),
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.zero),
child: Text(
"Done",
),
onPressed: () => {},
),
],
),
Flexible(
child: CupertinoDatePicker(
initialDateTime:
DateTime.now().add(new Duration(days: 7)),
minimumDate: DateTime.now(),
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (date) {
setState(() {
print(date);
_selectedDueDate = formatter.format(date);
});
},
),
),
],
),
);
});
},
),
);
}
}
將CupertinoDatePicker
包裹在Container
中並設置所需的height
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.