Flutter: Set edge color of the BottomAppBar() - flutter

I have a BottomAppBar() widget
BottomAppBar(
shape: CircularNotchedRectangle(),
color: Colors.orange,
notchMargin: 5,
child:Container(),
);
And, I want to set the edge color differently like the answer from this question.
How do I change Bottom App Bar Items Color?
I'd tried to set the color of the child Container(). However, it draws a straight line without the bump at the FloatingAppButton(). Is there any way that I can do this?

Do you want to like this, please check the below code
Source code
Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
backgroundColor: Colors.orange,
onPressed: () {},
),
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 6,
elevation: 30,
child: new Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(icon: Icon(Icons.menu), onPressed: () {},),
IconButton(icon: Icon(Icons.search), onPressed: () {},),
],
),
),
appBar: AppBar(
titleSpacing: 0,
title: Text("Test"),
backgroundColor: const Color(0xffFA7343),
),
body: Container(
),
)

Related

how you can remove the padding between the icon for the drawer in the appBar and the Search Icon in flutter

i make appBar and add a drawer to it and also search icon the problem there is padding between the icon for the Drawer and the search icon And I can't get rid of it
this the code:
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
titleSpacing: 0,
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
),
],
),
backgroundColor: Color(0xffffffff),
elevation: 1,
toolbarHeight: 40.0,
iconTheme: IconThemeData(color: Colors.grey),
),
drawer: Drawer(
child: ListView(
children: <Widget>[],
),
),
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Color(0xfffafafa),
child: Text("hello"),
),
);
}
}
Add this lines to remove default padding of IconButton:
IconButton(
constraints: BoxConstraints(),
padding: const EdgeInsets.all(0),),
Wrapping your search button with this will reduce the padding.
Not sure how much of the padding you wanted to remove.
SizedBox(
width: 10.0,
child: IconButton(
padding: EdgeInsets.zero,
icon: Icon(Icons.search),
onPressed: () {},
),
),
Try like this
appBar: AppBar(
title: Text(title),
backgroundColor: kPrimaryLightColor,
actions: <Widget>[
Padding(
padding: EdgeInsets.only(right: 20.0),
child: GestureDetector(
onTap: () {},
child: Icon(
Icons.message_rounded,
size: 30.0,
),
)),
Solution 1
Just add a property called "titleSpacing" in your AppBar Tag,
Sample
appBar: AppBar(
titleSpacing: 0, //Add this line to your code
title: Text(widget.title),
leading: Icon(Icons.android),
),
Solution 2
Or wrap your title with "Transform.translate" and Add property "offset".
sample
title: Transform.translate(
offset: Offset(-30.0, 0.0),
child: Text('your app title')
),

How to have 2 Floating Action Buttons fixed in some specific positions with Flutter?

I am developing an app with Flutter, and I want to have 2 FABs on the main screen. One in the BottomAppBar which I have done.
Scaffold(
appBard: AppBar(title: Text("My App")),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: ()=>{}
),
bottomNavigationBar: BottomAppBar(
color: Style.darkPrimaryColor,
shape: CircularNotchedRectangle(),
child: Container(
height: 50,
child: Row(
children: <Widget>[]
),
),
),
)
I want to have a second FAB positioned and fixed in the right bottom side of the screen in plus of the centered FAB like the following maquette:
Is there any way to achieve that?
I don't think there is any built in way of doing this with the scaffold, but it should be easy enough to just use a stack as your scaffold body, since you can add a floating action button anywhere. However, if you have two, you will need to change the hero tag on one of them to avoid errors when moving to/from that page.
Scaffold(
appBar: AppBar(title: Text("My App")),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: ()=>{}
),
bottomNavigationBar: BottomAppBar(
color: Style.darkPrimaryColor,
shape: CircularNotchedRectangle(),
child: Container(
height: 50,
child: Row(
children: <Widget>[]
),
),
),
body: Stack(
alignment: Alignment.bottomRight,
children: [
Container(
child: //Use this as if it were the body
),
//Setup the position however you like
Padding(
padding: const EdgeInsets.all(16.0),
child: FloatingActionButton(
heroTag: null, //Must be null to avoid hero animation errors
child: Icon(Icons.add),
onPressed: () => {},
),
),
],
),
)
Try this:
Scaffold(
appBar: AppBar(title: Text("My App")),
body: Stack(
children: [
Positioned(
bottom: 16,
right: 16,
child: FloatingActionButton(
heroTag: null,
child: Icon(Icons.add),
onPressed: ()=>{}
),
),
],
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: ()=>{}
),
bottomNavigationBar: BottomAppBar(
color: Colors.black54,
shape: CircularNotchedRectangle(),
child: Container(
height: 50,
child: Row(
children: <Widget>[
]
),
),
),
)

Flutter Floating Action Button location problem

I have added a floating action button in the bottomNavigationBar. The default location should be on the bottom right, but mine stays at the center.
I have tried using this floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
but the FAB still resides at the center screen.
Here is my full code of the screen:
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(55.0),
child: CustomAppBar(title: 'Customers (2)',),
),
drawer: Theme(
data: Theme.of(context).copyWith(
canvasColor: Colors.white
),
child: MyDrawer(),
),
body: Container(
padding: EdgeInsets.all(15.0),
decoration: BoxDecoration(color: Colors.white),
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
FaIcon(FontAwesomeIcons.search, color: Colors.greenAccent,),
SizedBox(width: 15.0,),
Text("Search Customers"),
],
),
],
),
),
),
bottomNavigationBar: FloatingActionButton(
child: FaIcon(FontAwesomeIcons.plus),
backgroundColor: Colors.greenAccent,
foregroundColor: Colors.white,
splashColor: Colors.black,
onPressed: () {
},
),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
);
}
Any idea how to solve this?
Replace:
bottomNavigationBar: FloatingActionButton(...)
with:
floatingActionButton: FloatingActionButton(...)

Flutter offset the appbar title to the left

I am creating page for my application and I have created the appbar with a leading icon. However, the space between the icon and the title is very large and to me, looks off.
I do I offset/push the title of the appbar to the left a little.
code:
appBar: AppBar(
leading: Builder(
builder: (BuildContext context) {
return IconButton(
icon: const Icon(Icons.chevron_left),
iconSize: MediaQuery.of(context).size.width * 0.1,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
onPressed: () => Navigator.of(context).pop(),
);
},
),
title: Text("Student Finance",
style: TextStyle(color: Colors.white),
),
),
Screenshot:
// Add everything under title widgets and make leading false
AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
IconButton(
onPressed: () => Navigator.pop(context),
icon: const Icon(Icons.chevron_left, size: 32.0),
),
Text("Student Finance"),
],
),
titleSpacing: 0.0,
automaticallyImplyLeading: false,
),

BottomAppBar Floating action button notch/inset is not transparent

I've added a BottomAppBar to scaffold in a materialApp, and to that I've added a fab with a inset at the center. The code looks somewhat like this
Scaffold(
bottomNavigationBar: BottomAppBar(
color: Theme.of(context).accentColor,
shape: CircularNotchedRectangle(),
child: _buildBottomBar(context),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
backgroundColor: Theme.of(context).primaryColor,
child: Center(
child: Icon(
Icons.add,
size: 32.0,
),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CreateEvent()),
);
},
),
)
And this is what I'm getting after rendering:
The notch is not transparent, and the content behind it is getting hidden.
Is there a way to fix this? Something I might have missed?
You just need to be on the flutter channel: master and then add to Scaffold:
Scaffold(
extendBody: true
);
and it should be transparent :)
Greets
Rebar
UPDATE:
You don't need to be on master channel. It's included everywhere :)
The problem is if you put your content in the body of Scaffold it won't overlap the size of your AppBar, BottomAppBar.
You can try using Stack, put your body as a first child, then put the Scaffold, change the backgroundColor as Transparent.
#override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
Align(
alignment: Alignment.bottomCenter,
child: Image.network(
"https://images.pexels.com/photos/255379/pexels-photo-255379.jpeg?auto=compress&cs=tinysrgb&h=350"),
),
Scaffold(
backgroundColor: Colors.transparent,
bottomNavigationBar: BottomAppBar(
color: Theme.of(context).accentColor,
shape: CircularNotchedRectangle(),
child: Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.access_alarm),
onPressed: () => null,
),
IconButton(
icon: Icon(Icons.sms_failed),
onPressed: () => null,
),
],
),
),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
backgroundColor: Theme.of(context).primaryColor,
child: Center(
child: Icon(
Icons.add,
size: 32.0,
),
),
onPressed: () {
/*
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CreateEvent()),
);*/
},
),
),
],
);
I was able to achieve the desired behavior by also setting the resizeToAvoidBottomInset flag to false.
#override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
resizeToAvoidBottomInset: false,
body: IndexedStack(
children: <Widget>[],
index: _selectedTab,
),
bottomNavigationBar: ClipRRect(
clipBehavior: Clip.antiAlias,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16.0),
topRight: Radius.circular(16.0)
),
child: BottomNavigationBar(
backgroundColor: Colors.white,
elevation: 10,
type: BottomNavigationBarType.fixed,
items: <BottomNavigationBarItem>[],
currentIndex: _selectedTab,
),
),
);
}
Edit: keep in mind that you may have to manually set the bottom insets by using MediaQuery.of(context)
Adding to the accepted solution, if you are using SafeArea as an immediate child to Scaffold then make sure you set the bottom property to false.
Scaffold(
extendBody: true,
...
child: SafeArea(
bottom: false, /* important */
child: Container(
child: // your app content
),
),
);
This enables the content to flow behind the BottomNavigationBar