Quantcast
Channel: How to create a custom AppBar widget? - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Answer by Ketan Ramani for How to create a custom AppBar widget?

$
0
0

widget_appbar.dart

class WidgetAppBar extends StatelessWidget implements PreferredSizeWidget {  final Color? backgroundColor;  final Color? textIconColor;  final String? icon;  final String? title;  final double? height;  final List<Widget>? menuItem;  final bool hideBack;  WidgetAppBar({    this.backgroundColor = whiteColor,    this.textIconColor = headingColor,    this.icon,    this.title = '',    this.menuItem,    this.height: kToolbarHeight,    this.hideBack = false,  });  @override  Size get preferredSize => Size.fromHeight(height!);  @override  Widget build(BuildContext context) {    return AppBar(      actions: menuItem,      toolbarHeight: preferredSize.height,      iconTheme: IconThemeData(        color: textIconColor,      ),      leading: hideBack          ? Container()          : icon == null              ? BackButton()              : IconButton(                  icon: Image.asset(                    icon!,                    height: 18,                    width: 18,                  ),                  onPressed: () {                    Navigator.pop(context, true);                  },                ),      title: Text(        title!,        style: TextStyle(          fontSize: 20,          fontWeight: FontWeight.bold,          color: textIconColor,        ),      ),      backgroundColor: backgroundColor,      centerTitle: true,    );  }}

How to use?

@overrideWidget build(BuildContext context) {  return Scaffold(    appBar: WidgetAppBar(      icon: ic_back_black,      title: 'Toolbar Title',    ),    body: SafeArea(      child: Container(),    ),  );}

Viewing all articles
Browse latest Browse all 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>