Flutter Scaffold自定义

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(),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值