flutter组件之SafeArea

flutter组件之SafeArea

自我理解:

把布局始终显示在首页页面的安全区域,用于适配各种异型屏幕(但是我试了一下 手机有限用的华为荣耀的刘海屏没有什么作用呀)
[官网api地址]https://api.flutter.dev/flutter/widgets/SafeArea-class.html
api里的视频把效果说的很明白,但是需要自备梯子

上代码:

class SafeAreaDemo extends StatefulWidget{
  @override
  State createState() {
    return _SafeAreaState();
  }

}
class _SafeAreaState extends State{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        top: false,
        bottom: false,
        left: false,
        right: false,
        child: ListView(
          children: List.generate(100, (i)=> Text('this is some textthis is some textthis is some text'+i.toString())),
        ),
      )
    );
  }

}

现象

当top值为true时
flutter组件之SafeArea_第1张图片
当top值为false时
flutter组件之SafeArea_第2张图片

你可能感兴趣的:(flutter)