I'm new to flutter. I'm trying to create a custom appbar widget and importing the widget in pages.
But I was unable to create the widget.
import 'package:flutter/material.dart'; class AppBar extends StatelessWidget{ @override Widget build(BuildContext context){ return AppBar( title: Text('Ordering'), actions: <Widget>[ IconButton( onPressed: _incrementCounter, icon: Icon(Icons.add), ), BadgeIconButton( itemCount: _counter, badgeColor: Color.fromRGBO(37, 134, 16, 1.0), badgeTextColor: Colors.white, icon: Icon(Icons.shopping_cart, size: 30.0,), onPressed: () {} ), ], );
} }'
An app bar consists of a toolbar and potentially other widgets, such as a TabBar and a FlexibleSpaceBar. App bars typically expose one or more common actions with IconButtons which are optionally followed by a PopupMenuButton for less common operations (sometimes called the "overflow menu").
You can add an icon to the AppBar by adding an IconButton widget to the actions list of the AppBar.
if you want to make a custom appbar in a different file so that it can be shared you can just make your new app bar extend it and then pass your customization to super(), in your case your KainAppBar will extend the GradientAppBar like below how MyAppBar extends AppBar.
import 'package:flutter/material.dart'; class CustomAppBar extends StatefulWidget implements PreferredSizeWidget { CustomAppBar({Key key}) : preferredSize = Size.fromHeight(kToolbarHeight), super(key: key); @override final Size preferredSize; // default is 56.0 @override _CustomAppBarState createState() => _CustomAppBarState(); } class _CustomAppBarState extends State<CustomAppBar>{ @override Widget build(BuildContext context) { return AppBar( title: Text("Sample App Bar") ); } }
Hopefully this helps
class AppBars extends AppBar { AppBars():super( iconTheme: IconThemeData( color: Colors.black, //change your color here ), backgroundColor: Colors.white, title: Text( "this is app bar", style: TextStyle(color: Color(Constant.colorBlack)), ), elevation: 0.0, automaticallyImplyLeading: false, actions: <Widget>[ IconButton( icon: Icon(Icons.notifications), onPressed: () => null, ), IconButton( icon: Icon(Icons.person), onPressed: () => null, ), ], ); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With