简体   繁体   中英

CupertinoDatePicker A RenderFlex overflowed by Infinity pixels on the bottom

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);
                                });
                              },
                            ),
                          ],
                        ),
                      );
                    });
              },
            ),

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);
                            });
                          },
                        ),
                      ),
                    ],
                  ),
                );
              });
        },
      ),
    );
  }
}

Wrap CupertinoDatePicker in a Container and set the desired height .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM