Flutter 自定义 AppBar

import 'package:flutter/cupertino.dart';

import 'package:flutter/material.dart';

import 'package:flutter_nxj_c/helpers/constants.dart';

import 'package:flutter_svg/svg.dart';

import 'dart:io';

///@autor Cc

///标题栏

class CustomAppBarextends PreferredSize {

///显示的标题栏Widget

  final WidgetchildView;

  ///标题

  final Stringtitle;

  ///返回的回调

  final FunctioncallPopBack;

  ///设置右边的显示区域Widget

  final WidgetrightWidget;

  ///显示底部的线

  final boolshowBottomLine;

  CustomAppBar(

{this.childView,

      this.title,

      this.callPopBack,

      this.rightWidget,

      this.showBottomLine})

:super(

preferredSize:

Size.fromHeight((Platform.isIOS ?44.0 : kToolbarHeight)));

  @override

  Widgetbuild(BuildContext context) {

Widget current =childView;

    if (childView ==null) {

current =Container(

margin:EdgeInsets.only(top: MediaQuery.of(context).padding.top),

        child:Stack(

children: [

Container(

decoration:BoxDecoration(

color: Colors.transparent,

                  border:Border(

bottom:BorderSide(

width:0.5,

                      color:Color((showBottomLine ??true)

? AppColors.borderColor

                          :0xffffffff),

                    ),

                  )),

              child:Center(

child:Text(

"${title ??"无标题"}",

                  style: (TextStyle(fontSize:16, fontWeight: FontWeight.w600)),

                ),

              ),

            ),

            Center(

child:Row(

mainAxisAlignment: MainAxisAlignment.spaceBetween,

                children: [

IconButton(

onPressed: () {

Navigator.pop(context);

                      callPopBack();

                    },

                    icon:SvgPicture.asset(

'assets/icons/common/ic_notify_normal_back.svg'),

                  ),

                  getRightWidget(),

                ],

              ),

            ),

          ],

        ),

      );

    }

return current;

  }

///获取右边的按钮显示区域

  WidgetgetRightWidget() {

if (rightWidget ==null) {

return SizedBox();

    }else {

return rightWidget;

    }

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容