Reputation: 448
I try to add a row of cancel and done button above the CupertinoDatePicker inside the Container but however hit error, what could possible go wrong?
════════ Exception caught by rendering library ═════════════════════════════════ A RenderFlex overflowed by Infinity pixels on the bottom. The relevant error-causing widget was 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);
});
},
),
],
),
);
});
},
),
Upvotes: 2
Views: 1322
Reputation: 54377
You can copy paste run full code below
You can wrap CupertinoDatePicker
with Flexible
code snippet
Flexible(
child: CupertinoDatePicker(
working demo
full code
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);
});
},
),
),
],
),
);
});
},
),
);
}
}
Upvotes: 3