Flutter UI开发与数据展示全攻略
1. 使用MediaQuery获取屏幕尺寸
在开发响应式界面时,了解设备的屏幕尺寸和配置信息至关重要。 MediaQuery 类可以帮助我们获取这些信息。以下是一个使用 MediaQuery 获取屏幕尺寸、宽高比、方向等信息的示例代码:
Text(
'You can Fit One column here!',
style: TextStyle(fontSize: 30, color: Colors.grey),
),
const SizedBox(height: 10.0),
Text(
'Screen Width: ${MediaQuery.of(context).size.width}',
style: const TextStyle(fontSize: 20, color: Colors.grey),
),
Text(
'Screen Height: ${MediaQuery.of(context).size.height}',
style: const TextStyle(fontSize: 20, color: Colors.grey),
),
Text(
'Aspect Ratio: ${MediaQuery.of(context).size.aspectRatio}',
style: const TextStyle(fontSize: 20, color: Colors.grey),
),
Text(
'Orientation: ${MediaQuery.of(context).orient
超级会员免费看
订阅专栏 解锁全文
1204

被折叠的 条评论
为什么被折叠?



