Icons get together in flutter bottom navigation bar with floating button - flutter

I'm making a bottom navigation bar using Inkwell, but as much as I tried solutions, I couldn't separate each icon in its respective space, I don't know what is failing me.
I tried with materialbuttom but the result was almost the same, although if there is any other alternative or suggestion I would like to know! Thankyou
I added the code
bottomNavigationBar: BottomAppBar(
shape: const CircularNotchedRectangle(),
notchMargin: 10,
child: SizedBox(
height: 60,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Material(
child: Center(
child: InkWell(
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () {
setState(() {
currentTab = 0;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.home),
Text("Home"),
//const Padding(padding: EdgeInsets.all(10))
],
),
),
),
),
Material(
child: Center(
child: InkWell(
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () {
setState(() {
currentTab = 1;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.group),
Text("Grupos"),
//const Padding(padding: EdgeInsets.only(left: 10))
],
),
),
),
),
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Material(
child: Center(
child: InkWell(
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () {
setState(() {
currentTab = 2;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.checklist_outlined),
Text("Completadas"),
//const Padding(padding: EdgeInsets.only(right: 10))
],
)),
),
),
Material(
child: Center(
child: InkWell(
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () {
setState(() {
currentTab = 3;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.person),
Text("Perfil")
//const Padding(padding: EdgeInsets.only(left: 10))
],
),
),
),
),
],
),
],
),
),
),

We can think bottomNavigationBar contains 5 widgets, one of the widget is FloatingActionButton. Therefor, we will include another widget as middle item of row's children that will cover FloatingActionButton space.
While items may have different sizes, we also need to align properly. We can wrap every widget with Expanded. ALso you can test with crossAxisAlignment: CrossAxisAlignment.stretch, or using LayoutBuilders constraints width on each item. If you find text overflow, you can wrap Flexible(child: Text(). More about text on overflow
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(child: Material(...)),
Expanded(child: Material(...)),
Expanded(child: const SizedBox()), // this will handle the fab spacing
Expanded(child: Material(...)),
Expanded(child: Material(...)),
]

try this
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
),
bottomNavigationBar: BottomAppBar(
shape: const CircularNotchedRectangle(),
notchMargin: 10,
child: SizedBox(
height: 60,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Material(
child: Center(
child: InkWell(
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () {
setState(() {
currentTab = 0;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.home),
Text("Home"),
//const Padding(padding: EdgeInsets.all(10))
],
),
),
),
),
Material(
child: Center(
child: InkWell(
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () {
setState(() {
currentTab = 1;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.group),
Text("Grupos"),
//const Padding(padding: EdgeInsets.only(left: 10))
],
),
),
),
),
SizedBox(),//to make space for the floating button
Material(
child: Center(
child: InkWell(
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () {
setState(() {
currentTab = 2;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.checklist_outlined),
Text("Completadas"),
//const Padding(padding: EdgeInsets.only(right: 10))
],
)),
),
),
Material(
child: Center(
child: InkWell(
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: () {
setState(() {
currentTab = 3;
});
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.person),
Text("Perfil")
//const Padding(padding: EdgeInsets.only(left: 10))
],
),
),
),
),
],
),
),
),
Result looks like this

Try below code hope its help to you, I have try another way.
You can refer here some packages for
return Scaffold(
body: Center(
child: Text(
'Hello, World!',
style: Theme.of(context).textTheme.headline4,
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 5,
child: Row(
//children inside bottom appbar
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(
Icons.home,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.group,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.checklist,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.person,
),
onPressed: () {},
),
],
),
),
);
Your Result Screen->

Related

Shaping appbar in flutter

Someone asked this question before with no straight answer:
Is there a way to shape the appbar to look like this photo ?
i dont think you can do it with the AppBar widget, but you can build your own like this:
not my best code but i think this can help you have an idea on how to do it
Widget build(BuildContext context)
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {}, icon: const Icon(Icons.arrow_back)),
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
IconButton(
onPressed: () {}, icon: const Icon(Icons.search)),
IconButton(
onPressed: () {},
icon: const Icon(Icons.notifications),
),
],
)
],
),
SizedBox(
height: 40,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30), color: Colors.green),
height: MediaQuery.of(context).size.height,
)
],
),
)),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}`

Flutter ButtonBar in horizontal mode doesn't seem to respect MainAxisSize

I would like to use flutter's ButtonBar due to the nice feature of automatically having a column when the device's width isn't enough. However, I'd also like to use the MainAxisSize.min, but I can't get it to use MainAxisSize.min in horizontal mode (wrt width). See example below.
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
decoration: BoxDecoration(border: Border.all()),
child: ButtonBar(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
FlatButton(
child: Text('short'),
color: Colors.blueAccent,
onPressed: () => {},
),
FlatButton(
child: Text('short'),
color: Colors.blueAccent,
onPressed: () => {},
),
],
),
),
Container(
decoration: BoxDecoration(border: Border.all()),
child: ButtonBar(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
FlatButton(
child: Text('loooooooooooooooooong'),
color: Colors.blueAccent,
onPressed: () => {},
),
FlatButton(
child: Text('loooooooooooooooooong'),
color: Colors.blueAccent,
onPressed: () => {},
),
],
),
),
],
),
What I get
What I want
A possible solution can be to use the Wrap class instead of the ButtonBar. You have to
wrap the Container with a Center widget add some padding for the layout and your're god to go:
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
decoration: BoxDecoration(border: Border.all()),
child: ButtonBar(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
FlatButton(
child: Text('short'),
color: Colors.blueAccent,
onPressed: () => {},
),
FlatButton(
child: Text('short'),
color: Colors.blueAccent,
onPressed: () => {},
),
],
),
),
Center(
child: Container(
decoration: BoxDecoration(border: Border.all()),
padding: EdgeInsets.all(10),
child: Wrap(
//alignment: MainAxisAlignment.center,
//mainAxisSize: MainAxisSize.max,
children: <Widget>[
FlatButton(
child: Text('looooooooooooooooooooooooong'),
color: Colors.blueAccent,
onPressed: () => {},
),
FlatButton(
child: Text('looooooooooooooooooooooooong'),
color: Colors.blueAccent,
onPressed: () => {},
),
],
),
),
),
],
),

Duplicate named argument - how to add more then one child to a body in flutter?

import 'package:flutter/material.dart';
Error in line 18:
Error: The argument for the named parameter 'child' was already specified. Try removing one of the named arguments, or correcting one of the names to reference a different named parameter.dart(duplicate_named_argument)
Why body can't have more then one child?
How to solve that?
class mainMenu extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Bar Iland"),
),
body: Center(
child:
Image.asset(
'assets/Bar_Iland_line.png',
height: 200,
color: Colors.black.withOpacity(0.80),
),
child:
Column(
children: <Widget>[
Spacer(flex: 8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children:[
SizedBox.fromSize(
size: Size(90, 90), // button width and height
child: ClipOval(
child: Material(
color: Colors.orange, // button color
child: InkWell(
splashColor: Colors.green, // splash color
onTap: () {}, // button pressed
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.call), // icon
Text("Call"), // text
],
),
),
),
),
),
SizedBox.fromSize(
size: Size(90, 90), // button width and height
child: ClipOval(
child: Material(
color: Colors.orange, // button color
child: InkWell(
splashColor: Colors.green, // splash color
onTap: () {}, // button pressed
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.call), // icon
Text("Call"), // text
],
),
),
),
),
),
SizedBox.fromSize(
size: Size(90, 90), // button width and height
child: ClipOval(
child: Material(
color: Colors.orange, // button color
child: InkWell(
splashColor: Colors.green, // splash color
onTap: () {}, // button pressed
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.call), // icon
Text("Call"), // text
],
),
),
),
),
),
],
),
Spacer(flex: 1),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children:[
SizedBox.fromSize(
size: Size(90, 90), // button width and height
child: ClipOval(
child: Material(
color: Colors.orange, // button color
child: InkWell(
splashColor: Colors.green, // splash color
onTap: () {}, // button pressed
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.call), // icon
Text("Call"), // text
],
),
),
),
),
),
SizedBox.fromSize(
size: Size(90, 90), // button width and height
child: ClipOval(
child: Material(
color: Colors.orange, // button color
child: InkWell(
splashColor: Colors.green, // splash color
onTap: () {}, // button pressed
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.call), // icon
Text("Call"), // text
],
),
),
),
),
),
SizedBox.fromSize(
size: Size(90, 90), // button width and height
child: ClipOval(
child: Material(
color: Colors.orange, // button color
child: InkWell(
splashColor: Colors.green, // splash color
onTap: () {}, // button pressed
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.call), // icon
Text("Call"), // text
],
),
),
),
),
),
],
),
Spacer(flex: 10),
],
),
),
);
}
}
As pskink mentioned, you can't have two children in a body.
Use
Scaffold(
body: Column( // or Row or Wrap
children: [
Child1(),
Child2(),
]
)
)

IconButton's ripple effect appears under the widget

I have a Container widget and an IconButton. When I press on the IconButton, ripple effect shows behind the Container. Is there a way to fix this?
Here is the full class as Github Gist.
Container(
height: height,
decoration: _cardBoxDecoration(Colors.white),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(
FontAwesomeIcons.checkCircle,
color: _checkGrey,
size: 20,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.more_horiz,
color: _grey,
size: 20,
),
onPressed: () {},
)
],
),
]
)
);
You can use the Material widget to get the output you want. Replace the Container Widget with Material Widget.
class _AppointmentsCart extends StatelessWidget {
final double height;
_AppointmentsCart({this.height});
#override
Widget build(BuildContext context) {
return Material( // replace container widget
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20))),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(
FontAwesomeIcons.checkCircle,
color: _grey,
size: 20,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.more_horiz,
color: Colors.grey,
size: 20,
),
onPressed: () {},
)
],
),
Padding(
padding: EdgeInsets.only(left: 15),
child: Text(
'Today',
style: TextStyle(fontSize: 18),
),
),
Padding(
padding: const EdgeInsets.all(15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'5',
style: TextStyle(fontSize: 24, color: _titleGrey),
),
Text(
'Appoinemts',
style: TextStyle(fontSize: 12, color: _subtitleGrey),
)
],
),
)
],
),
);
}
}

How to show a Container fixed at bottom of screen without using bottom navigation bar in Flutter?

In my flutter project, I have a container with some icons and text below them. I want this entire container to be fixed at bottom of the screen without using bottom navigation bar like the below image-
So, I need an entire example to fix that container at bottom and keep my other components inside body with a scroll view.
Ok,
Here you go....
return Scaffold(
appBar: AppBar(
title: Text("Header"),
),
body: Column(
children: <Widget>[
Expanded(
child: Container(
alignment: Alignment.center,
child: Text("Hello"),
),
),
Container(
height: 50,
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_downward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_left), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_upward), onPressed: (){},),
],
),
)
],
),
);
If you want to make a scrollable item/listview in the body section and want a fixed bottom container you can follow this code given below :
important note : Make sure wrap the listview with Expanded
import 'package:flutter/material.dart';
class ShoppingCart extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[200],
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
),
actions: <Widget>[
GestureDetector(
onTap: () {
//your code
},
child: Padding(
padding: const EdgeInsets.only(right: 15.0),
child: Icon(
Icons.delete_outline_sharp,
color: Colors.black,
size: 30,
),
)),
//Add more icon here
],
elevation: 0,
centerTitle: false,
title:
Text("Shopping Cart", style: TextStyle(color: Colors.black))),
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: shoppingCartItems.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(
top: 15.0, left: 12.0, right: 12.0),
child: Container(
decoration: BoxDecoration(
// color: Color(0xffF3F3F3),
color: Colors.red,
shape: BoxShape.rectangle,
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
height: 120,
width: 360,
),
);
},
),
),
Container(
height: 150,
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.deepOrange[200],
borderRadius:
BorderRadius.vertical(top: Radius.circular(20.0))),
)
],
));
}
}
Update :
This is built in now. You can use bottomNavigationBar and customize is as below :
bottomNavigationBar: BottomAppBar(
child: Container(
height: //set your height here
width: double.maxFinite, //set your width here
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){
//on Presses functionaluty goes here
},),
//add as many tabs as you want here
],
),
),
),
bottomNavigationBar: BottomAppBar(
child: Container(
height: 50.0,
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_downward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_left), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_upward), onPressed: (){},),
],
),
),
),