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

///標(biāo)題欄

class CustomAppBarextends PreferredSize {

///顯示的標(biāo)題欄Widget

? final WidgetchildView;

? ///標(biāo)題

? final Stringtitle;

? ///返回的回調(diào)

? final FunctioncallPopBack;

? ///設(shè)置右邊的顯示區(qū)域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 ??"無標(biāo)題"}",

? ? ? ? ? ? ? ? ? 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;

? }

///獲取右邊的按鈕顯示區(qū)域

? WidgetgetRightWidget() {

if (rightWidget ==null) {

return SizedBox();

? ? }else {

return rightWidget;

? ? }

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容