123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:liftmanager/res/colors.dart';
- import 'package:liftmanager/res/dimens.dart';
- import 'package:liftmanager/res/gaps.dart';
- import 'package:liftmanager/res/iconfont.dart';
- import 'package:liftmanager/routers/fluro_navigator.dart';
- /// 自定义AppBar
- class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
- const MyAppBar(
- {Key key,
- this.backgroundColor,
- this.title: "",
- this.centerTitle: "",
- this.actions,
- this.onPressed,
- this.fun,
- this.onBack,
- this.isFun: false,
- this.isBack: true,
- this.bgColors,
- this.titleColor = Colours.text_black,
- this.statubarStyle = SystemUiOverlayStyle.dark,
- this.isColorTopToBottom=false})
- : super(key: key);
- // SystemUiOverlayStyle.dark
- final Color backgroundColor;
- final String title;
- final String centerTitle;
- final List<Widget> actions;
- final VoidCallback onPressed;
- final bool isBack;
- final Function fun;
- final bool isFun;
- final VoidCallback onBack;
- final List<Color> bgColors;
- final Color titleColor;
- final SystemUiOverlayStyle statubarStyle;
- final bool isColorTopToBottom;
- @override
- Widget build(BuildContext context) {
- return AnnotatedRegion<SystemUiOverlayStyle>(
- value: statubarStyle,
- child: Container(
- color: bgColors == null
- ? backgroundColor == null
- ? Colors.white
- : backgroundColor
- : null,
- decoration: bgColors != null
- ? BoxDecoration(
- gradient: LinearGradient(
- begin: isColorTopToBottom?Alignment.topCenter:Alignment.centerLeft,
- end: isColorTopToBottom?Alignment.bottomCenter:Alignment.centerRight,
- colors: bgColors,
- ),
- )
- : null,
- child: SafeArea(
- child: Stack(
- alignment: Alignment.centerLeft,
- children: <Widget>[
- Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Container(
- alignment: centerTitle.isEmpty
- ? Alignment.centerLeft
- : Alignment.center,
- width: double.infinity,
- child: Text(title.isEmpty ? centerTitle : title,
- style: TextStyle(
- fontSize: Dimens.font_sp18,
- color: titleColor,
- )),
- padding: const EdgeInsets.symmetric(horizontal: 48.0),
- )
- ],
- ),
- isBack
- ? IconButton(
- onPressed: () {
- // FocusScope.of(context).unfocus();
- // if(isFun){
- // fun();
- // }else {
- // Navigator.maybePop(context);
- // }
- if (onBack != null) {
- onBack();
- } else if (isFun) {
- fun();
- FocusScope.of(context).unfocus();
- } else {
- FocusScope.of(context).unfocus();
- NavigatorUtils.goBackWithParams(context, true);
- }
- },
- tooltip: 'Back',
- padding: const EdgeInsets.all(12.0),
- icon: Icon(
- Iconfont.fanhui,
- size: 17,
- color: titleColor,
- ),
- )
- : Gaps.empty,
- Positioned(
- right: 10,
- child: Theme(
- data: Theme.of(context).copyWith(
- buttonTheme: ButtonThemeData(
- padding: const EdgeInsets.symmetric(horizontal: 16.0),
- minWidth: 60.0,
- )),
- child: rightActions()),
- ),
- ],
- ),
- ),
- ),
- );
- }
- Widget rightActions() {
- if (this.actions != null && this.actions.isNotEmpty) {
- return Row(
- children: this.actions,
- );
- }
- return Container(child: null,);
- }
- @override
- Size get preferredSize => Size.fromHeight(48.0);
- }
|