Flutter 全面屏适配

220 阅读1分钟

方案一

SafeArea

SafeArea(
  child: Children(),
)

方案二

MediaQuery

@override
  Widget build(BuildContext context) {
    final EdgeInsets padding = MediaQuery.of(context).padding;
    return MaterialApp(
      title: '全面屏适配',
      home: Container(
        decoration: BoxDecoration(
          color: Colors.white,
        ),
        padding: EdgeInsets.fromLTRB(0, padding.top, 0, padding.bottom),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text('Top'),
            Text('Bottom'),
          ],
        ),
      ),
    );
  }

tip Android得修改最大长宽比

AndroidMainfest.xml

<meta-data
            android:name="android.max_aspect"
            android:value="2.3"
            />