flutter实用技巧-使用flutter_statusbar获取各种屏幕android,ios的状态栏高度

前言

flutter中貌似还没有什么api可以获取到系统的状态栏高度,所以就有了这个库

思路:

android获取状态栏高度:

public int getStatusBarHeight() {
  int result = 0;
  int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
  if (resourceId > 0) {
      result = getResources().getDimensionPixelSize(resourceId);
  }
  return result;
}

ios获取状态栏高度:

使用系统api可直接获取到状态栏的frame:

 [[UIApplication sharedApplication] statusBarFrame]

github

https://github.com/jzoom/flut...

使用方法:

安装

在项目中增加依赖:

flutter_statusbar: ^0.0.1

然后在as中点击下"package get"或者 在项目根目录下运行:

flutter package get

clipboard.png

使用:

import 'package:flutter_statusbar/flutter_statusbar.dart';

double   _height = await FlutterStatusbar.height;

clipboard.png

clipboard.png

是不是很简单呢。

评论

暂无评论