【问题标题】:How to make resposive ui for mobiles in flutter [duplicate]如何在颤动中为手机制作响应式用户界面[重复]
【发布时间】:2021-06-29 14:28:20
【问题描述】:

我观察到小部件在小屏幕上显示得更大,而在大屏幕上显示得更小。 在大屏幕上它看起来相当不错,但在小屏幕上看起来很奇怪。 如何在不同的手机屏幕尺寸下制作响应式且美观的 UI...??

【问题讨论】:

标签: flutter dart flutter-layout flutter-dependencies flutter-design


【解决方案1】:

您可以使用方法MediaQuery.of(context).size 来检索当前屏幕的大小并根据该值定义小部件的大小。
这是一个例子:

@override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width / 3.5,
      child: Center(
          child: Card(
              child: InkWell(
        onTap: () => _openUrl(_shortcut.url),
        child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: [
              Container(
                height: MediaQuery.of(context).size.height / 6,
                color: Color(int.parse("0xFF${_shortcut.color}")),
                child: Center(child: Icon(_shortcut.icon, color: Colors.white)),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(_shortcut.title,
                    style: TextStyle(fontWeight: FontWeight.bold)),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(
                  _shortcut.description,
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
            ]),
      ))),
    );
  }

【讨论】:

    猜你喜欢
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 2020-07-07
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    相关资源
    最近更新 更多