一、依赖
只需要原生io 和services 即可。
功能主要为可以自定义AppBar 及整体页面布局。
1. 状态栏管理
主要使用如下
import 'dart:io';
import 'package:flutter/services.dart';
SystemUiOverlayStyle value;
if(Platform.isAndroid){
value = SystemUiOverlayStyle(
statusBarColor: Colors.transparent, /// 安卓系统状态栏存在底色,所以需要加这个
statusBarIconBrightness: Brightness.dark, /// 状态栏字体颜色
);
} /// 仅IOS可直接使用:SystemUiOverlayStyle.dark, 状态栏主题色,表现为dart:黑色,light:白色
AnnotatedRegion<SystemUiOverlayStyle>(
value: value
child: Scaffold(
body: Widget
)
)
二、使用
import 'dart:io';
import 'package:flutter/services.dart';
customerTheme(bool inset, SystemUiOverlayStyle value, Widget body, {BoxDecoration? boxDecoration, Function()? onTap, bool willPop = false}){
if(Platform.isAndroid){
value = SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
);
}
return AnnotatedRegion<SystemUiOverlayStyle>(
value: value,
child: Scaffold(
resizeToAvoidBottomInset: inset, /// true时body和scaffold的浮动窗口小部件应自行调整大小,避免键盘弹出时溢出
body: willPop ? WillPopScope( /// 阻止左滑动或安卓返回键退出
onWillPop: () async {
return true;
},
child: GestureDetector(
onTap: onTap,
child: Container(
height: double.infinity,
width: double.infinity,
decoration: boxDecoration,
child: body,
margin: EdgeInsets.only(top: 10.dp),
),
),
) : GestureDetector(
onTap: onTap,
child: Container(
height: double.infinity,
width: double.infinity,
decoration: boxDecoration,
child: Column(
children: [
Get.getHeightBox(10.dp),
Expanded(child: body)
],
),
),
)
)
);
}
|