Search code examples
flutterflutter-layoutcupertino-widgets

Flutter CupertinoPicker UI breaks and children are not displayed properly


I am quite new to Flutter and was trying to implement the CupertinoPicker Widget. When I press a button I want to be able to replace the current CupertinoPicker with another one. Unfortunately when I try this the text from the second UI is quite distorted.

Here are some images to help you understand my issue. First Screen Faulty Screen

What exactly am I missing here?

Here is my code

Code on Github


Solution

  • Just wrap the Center widget with a Container widget. Here's a screenshot of the app and the code.

    enter image description here

    Widget _second() {
        return Container(
          child: Center(
            child: CupertinoPicker(
              selectionOverlay: null,
              onSelectedItemChanged: (value) {},
              itemExtent: 30,
              children: [
                Text("City 1"),
                Text("City 2"),
                Text("City 3"),
                Text("City 4"),
                Text("City 5"),
                Text("City 6"),
                Text("City 7"),
              ],
            ),
          ),
        );
      }