I want a BottomNavigationBar with 1 NavigationBarItem. The purpose is to display a record count for a list.
Can someone please advise me if there is a way to achieve that?
I can see no logical reason why the "items:" must exceed 1 item, but I'd be pleased to learn why.
Into bottomNavigationBar need to minimun 2 NavigationBarItem require. but you want a BottomNavigationBar with 1 NavigationBarItem, So you can use the Custom layout for the BottomNavigationBarItem for display 1 item into bottomNavigationBar
Custom Layout like as bellow :
bottomNavigationBar: Container(
height: 65,
color: Colors.grey,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
IconButton(
icon: Icon(Icons.list),
onPressed: (){},
),
Text("items"),
],
),
),
),
Another way to handle this and the way that I ended up using is to add an invisible BottomNavigationBarItem to the BottomNavigationBar. The way to do that is to just use icon: Icon(null) and an zero-length text. The reason that at least two items are needed in the BottomNavigationBar is possibly because of the docking capability of the FAB button which is a very useful feature.
Related
I am new in flutter.
I am following some YouTube videos to learn flutter. After adding a picture in card(home screen) now I want to add two buttons below that picture. how can i do it.
the picture Adding code
body: Center(
child: Card(
child: Column(
children: [Image.asset("assets/image-name")],
),
),
),
Here you have a great page, where you can find implementations of basic material widgets in Flutter.
For your example, it would look like this:
body: Center(
child: Card(
child: Column(
children: [
Image.asset("assets/image-name"),
ElevatedButton(
onPressed: () {
// Respond to button press
},
child: Text('CONTAINED BUTTON'),
)
],
),
),
),
For a second button, you can just add another one in the children array.
You can also wrap both buttons in Row widget, that will allow you to place them horizontally, next to each other.
How can I change the color of a ButtonBar in Flutter? There isn't a color in ButtonBarTheme as far as I can tell. I am trying to do something like this:
return Scaffold(
backgroundColor: Colors.red,
body: Center(child: Text('foo')),
// Somehow get the color of these buttons different to backgroundColor
persistentFooterButtons: _buildTextButtons(),
);
The best I can think of at the moment is to somehow reimplement the persistent footer buttons myself, but that is ugly. The problem seems to be that the Scaffold backgroundColor property is used in multiple places, yet is defined in a single widget. This means I can't wrap it in a Theme and override it piecemeal either, as far as I can tell.
Oh, I might have found an answer. I had been using both the bottomNavigationBar and the persistentFooterButtons. persistentFooterButtons are wrapped in a ButtonBar, which appears to limit your styling options.
bottomNavigationBar is a single widget, though, so you can fiddle with it. I switched to just build my own persistentFooterButtons after all.
(I had to edit this from my app, so it might not be copy/paste ready.)
Widget _buildNavigationBar(BuildContext ctx, Color barColor) {
List<Widget> actions = [
// We need the first element to be big, to push everything to the right.
Expanded(
child: Container(),
),
];
actions.addAll(_buildTextButtons(ctx));
Widget actionContainer = ColoredBox(
color: barColor,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
children: actions,
),
),
);
return Column(
mainAxisSize: MainAxisSize.min,
children: [
actionContainer,
// I use this to make space for ads.
Container(
color: barColor,
height: 50,
),
],
);
}
return Scaffold(
backgroundColor: Colors.red,
body: Center(child: Text('foo')),
// removed this persistentFooterButtons: _buildTextButtons(),
// and replaced with this:
bottomNavigationBar: _buildNavigationBar(ctx),
);
you can also wrap that ButtonBar into Container and After that, you can make any type of changes to that ButtonBar, like coloring etc
Trying to do something like this in Flutter (I'm totally beginner), I don't get how to nest some widgets... I've tried to put a Row() for floating action buttons and another Row for labels but they aren't aligned centered like the image. Should I use GridView instead? thanks!
You were right, but instead of use two rows use only one Row but with two Columns inside it, also with a row you can determine the position for each child according to the mainAxisAlignment and the crossAxisAlignment, for example to center the content use MainAxisAlignment.center as follows:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
children: [
FloatingActionButton(
onPressed: (){},
child: Icon(Icons.add),
),
Text(
"Test"
)
],
),
SizedBox(width: 16.0),
Column(
children: [
FloatingActionButton(
onPressed: (){},
child: Icon(Icons.add),
),
Text(
"Test"
)
],
),
],
)
If you want to see a little more about layouts in Flutter you can check the Building layouts tutorial section in the documentation.
I've already tried PrefixIcon for TextField in flutter but this time I'm looking for something like Postfix Clickable Icon in flutter. I'm attaching the image and I want to achieve something like that.
Where the Icon is clickable and on clicking the Icon it will display the other TextField.
Here's the Image:
Use a suffixIcon. If that doesn't behave how you'd expect, you can always use a Stack.
You can use a Stack Widget to do that. it works similar to a Row or a Column but its Stacks its children on top of each other.
https://api.flutter.dev/flutter/widgets/Stack-class.html
what you are trying to do this something like this,
Stack(
alignment: Alignment.centerRight,
children: <Widget>[
TextField(),
IconButton(icon: Icon(Icons.add), onPressed: (){
//Code
})
],
),
You can use a Stack Widget #Srilal Sachintha
Stack(
alignment: Alignment.centerRight,
children: <Widget>[
TextFormField(),
IconButton(icon: Icon(Icons.add), onPressed: (){
//Code
})
],
),
or Use a suffixIcon. If that doesn't behave how you'd expect, you can always use a Stack. #
I saved the google logo a as .png because I want to keep its colors. I am aware there are some packages for predefined sign-in buttons like google or with the google Icon(but I can't keep the colors obviously in this case), but I would like to know if I can somehow make so the .png image acts like an Icon.
You can use whatever button widget you like or you can create your custom button...
According to your image you can use outline button or flat button... then in your child parameter add Row with image and text
OutlineButton(child: Row(children: Image.asset(your_image_location), Text('Sign in with Google')))
body: Stack(
children: <Widget>[
Center(
child: IconButton(
icon: Image.asset('path/the_image.png'),
iconSize: 50,
onPressed: () {},
)
Positioned(
child: Container(
child: Center(child: Text('Sign in With Google')),
)),
],
)