import 'package:flutter/material.dart';
import 'focus_scope_close_utils.dart';
class FlutterAppBar {
static cupertinoAppBarSafeArea(
BuildContext context, {
String? title,
Widget? titleWidget,
List<Widget>? rightActions,
PreferredSizeWidget? bottom,
Color? backgroundColor,
Color? cupertinoAppBarColor,
bool showFeedBack = true,
double? elevation,
bool leading = true,
}) {
return AppBar(
title: titleWidget ??
Text(
title ?? "",
style: const TextStyle(
color: Colors.black, fontWeight: FontWeight.w500, fontSize: 18),
),
backgroundColor:
cupertinoAppBarColor ?? backgroundColor ?? const Color(0xffF7F7F7),
elevation: elevation ?? 0,
centerTitle: true,
leading: leading
? IconButton(
icon: Image.asset(
Assets.p2IcBack,
width: 10,
),
onPressed: () => Navigator.of(context).pop(),
)
: null,
bottom: bottom,
);
}
static cupertinoScaffoldSafeArea(
BuildContext context, {
Widget? child,
Widget? titleWidget,
String? title,
Color? backgroundColor,
List<Widget>? rightActions,
bool resizeToAvoidBottomInset = true,
PreferredSizeWidget? bottom,
bool showFeedBack = true,
Color? bottomColor,
Color? cupertinoAppBarColor,
bool leading = true,
bool appBar = true,
double? elevation,
}) {
return GestureDetector(
onTap: () {
try {
FocusScope.of(context).requestFocus(FocusNode());
} catch (w) {
//
}
},
child: Scaffold(
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
backgroundColor: backgroundColor ?? const Color(0xffF7F7F7),
appBar: appBar
? FlutterAppBar.cupertinoAppBarSafeArea(context,
title: title,
titleWidget: titleWidget,
rightActions: rightActions,
bottom: bottom,
leading: leading,
elevation: elevation,
showFeedBack: showFeedBack,
cupertinoAppBarColor: cupertinoAppBarColor ??
backgroundColor ??
const Color(0xffF7F7F7),
backgroundColor: backgroundColor)
: null,
body: Container(
width: double.infinity,
height: double.infinity,
color: bottomColor ?? backgroundColor ?? const Color(0xffF7F7F7),
child: Stack(
children: [
//顶部颜色
Container(
width: double.infinity,
color: backgroundColor ?? const Color(0xffF7F7F7),
height: 100,
),
SafeArea(
child: Container(
color: backgroundColor ?? const Color(0xffF7F7F7),
child: child ?? Container(),
),
)
],
),
),
),
);
}
}
Flutter Scaffold自定义
于 2023-11-15 16:44:33 首次发布