2

enter image description here I have a function which enables me to show the date picker with a button press.when I press the button I get this bottom overflow

3 Answers 3

3

I got this problem too, but I found a solution. Just wrap with FittedBox.

Future<Null> selecionarData() async {
//dataSelecionada is a final DateTime
dataSelecionada = await showDatePicker(
    context: context,
    initialDate: dataAtual,
    firstDate: DateTime(2019),
    lastDate: DateTime(2022),
    builder: (BuildContext context, Widget child) {
      return FittedBox(
        child: Theme(
          child: child,
          data: ThemeData(
            primaryColor: Colors.purple[300],
          ),
        ),
      );
    });

}

Sign up to request clarification or add additional context in comments.

1 Comment

With null safety you should use (BuildContext? context, Widget? child)
2

I solved this problem with this post: https://github.com/flutter/flutter/issues/19744

I basically remove the OK and CANCEL buttom from this, and added to when select date automatically press on one DATE on datepicker.

In yout datapicker.dart:

void _handleYearChanged(DateTime value) {
    _vibrate();
    setState(() {
      _mode = DatePickerMode.day;
      _selectedDate = value;
      Navigator.pop(context, _selectedDate); //new
    });
  }

  void _handleDayChanged(DateTime value) {
    _vibrate();
    setState(() {
      _selectedDate = value;
      Navigator.pop(context, _selectedDate); //new
    });
  }

I commented on lines 995 and 1017 in which you insert the action

  switch (orientation) {
            case Orientation.portrait:
              return new SizedBox(
                width: _kMonthPickerPortraitWidth,
                child: new Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    header,
                    new Container(
                     color: theme.dialogBackgroundColor,
                     child: new Column(
                       mainAxisSize: MainAxisSize.min,
                       crossAxisAlignment: CrossAxisAlignment.stretch,
                       children: <Widget>[
                         picker,
                         //actions,
                       ],
                     ),
                    ),
                  ],
                ),
              );
            case Orientation.landscape:
              return new SizedBox(
                height: _kDatePickerLandscapeHeight,
                child: new Row(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    header,
                    new Flexible(
                      child: new Container(
                        width: _kMonthPickerLandscapeWidth,
                        color: theme.dialogBackgroundColor,
                        child: new Column(
                          mainAxisSize: MainAxisSize.min,
                          crossAxisAlignment: CrossAxisAlignment.stretch,
                          children: <Widget>[picker] //, actions],
                        ),
                      ),
                    ),
                  ],
                ),
              );
          }

In my opinion, we don't need the CANCEL button and OK button.

Comments

1

This is a known issue https://github.com/flutter/flutter/issues/18672

There is a suggestion but that doesn't really solve the issue:

When the keyboard appears your app, including the dialog, is being resized to make room for it. This would also happen if you changed the device's orientation from portrait to landscape.

Wrapping the dialog's widget - the one you're building with showDialog's builder parameter - in a SingleChildScrollView or a ListView or a ClipRect (per the error message) will make it resizable.

2 Comments

in my code here I don't know where I can do that
using windows 1.22.5 stable build. You can just wrap with fitted box via builder. just add builder argument: (BuildContext context, Widget child) { return FittedBox( child: child, ); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.