【问题标题】:Flutter CupertinoTimerPicker does not fit to parent width or heightFlutter CupertinoTimerPicker 不适合父宽度或高度
【发布时间】:2020-05-09 15:57:27
【问题描述】:

我使用 double.infinity、SizedBox 和 SizeBox.expand 尝试了具有宽度和高度的容器。小部件不适合父宽度和高度。有人可以帮忙吗?

class _SetTimerButtonState extends State<SetTimerButton> {
  List<String> _timerPicker = ["0", "1", "2", "3"];
  Duration initialtimer = new Duration();

  @override
  Widget build(BuildContext context) {
    return Builder(
      builder: (context) => FlatButton(
        color: Colors.white,
        textColor: Colors.grey,
        disabledColor: Colors.grey,
        disabledTextColor: Colors.black,
        // padding: EdgeInsets.all(8.0),
        // splashColor: Colors.blueAccent,
        onPressed: () {
          showModalBottomSheet(
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(20.0),
            ),
            context: context,
            builder: (BuildContext builder) {
              return Container(
                height: MediaQuery.of(context).copyWith().size.height / 3,
                child: SizedBox.expand(
                  // height: double.infinity,
                  // width: double.infinity,
                  child: CupertinoTimerPicker(
                    mode: CupertinoTimerPickerMode.hms,
                    minuteInterval: 1,
                    secondInterval: 1,
                    initialTimerDuration: initialtimer,
                    onTimerDurationChanged: (Duration changedtimer) {
                      setState(() {
                        initialtimer = changedtimer;
                      });
                    },
                  ),
                )
              );
            }
          );
        },
        child: Row(
          children: <Widget>[
            Expanded(
              child: Text(
                "No Timer",
                style: TextStyle(fontSize: 20.0),
              ),
            ),
            Icon(Icons.arrow_forward_ios),
          ],
        ),
      )
    );
  }
}

【问题讨论】:

    标签: android flutter dart flutter-layout


    【解决方案1】:

    根据documentation,选择器的大小是固定的:

    选择器的固定大小为 320 x 216,以逻辑像素为单位,带有 CupertinoTimerPickerMode.hms 除外,它是 330 x 216。如果 父小部件提供了比它需要的更多的空间,选择器将 根据对齐属性定位自身。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多