I created my own bottom app bar following a tutorial. However, there is a white space between the bottom nav bar and the bottom of the screen. I colored this space in white to show it. How can I make my container the actual nav bar and hide that space?
This is happening on all of my screens in the app regardless if they begin with a scaffold, column, container etc.
import 'package:flutter/material.dart';
class bottomAppBar extends StatelessWidget {
const bottomAppBar({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return BottomAppBar(
color: Colors.white,
child: Container(
color: Color(0xFF313131).withOpacity(0.7),
height: 50,
width: double.maxFinite,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
onPressed: () {
Navigator.pushNamed(context, '/');
},
icon: Icon(
Icons.home,
color: Colors.white,
),
),
IconButton(
onPressed: () {
Navigator.pushNamed(context, '/discover');
},
icon: Icon(
Icons.search,
color: Colors.white,
),
),
IconButton(
onPressed: () {
Navigator.pushNamed(context, '/mybookings');
},
icon: Icon(
Icons.hello,
color: Colors.white,
),
),
IconButton(
onPressed: () {
Navigator.pushNamed(context, '/user');
},
icon: Icon(
Icons.person,
color: Colors.white,
),
),
],
),
),
);
}
}
This happens because you use the scaffold propery from the materail app. But, never wrap the widget with the scaffold widget.
After wraping the widget in scaffold use the bottomNavigationBar property to put your BottomAppBar. Then every thing will work perfect.
Thank you.
Code (Your updated code)
import 'package:flutter/material.dart';
class bottomAppBar extends StatelessWidget {
const bottomAppBar({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomAppBar(
color: Colors.white,
child: Container(
color: Color(0xFF313131).withOpacity(0.7),
height: 50,
width: double.maxFinite,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
onPressed: () {
// Navigator.pushNamed(context, '/');
},
icon: Icon(
Icons.home,
color: Colors.white,
),
),
IconButton(
onPressed: () {
// Navigator.pushNamed(context, '/discover');
},
icon: Icon(
Icons.search,
color: Colors.white,
),
),
IconButton(
onPressed: () {
// Navigator.pushNamed(context, '/mybookings');
},
icon: Icon(
Icons.ac_unit,
color: Colors.white,
),
),
IconButton(
onPressed: () {
// Navigator.pushNamed(context, '/user');
},
icon: Icon(
Icons.person,
color: Colors.white,
),
),
],
),
),
),
);
}
}
Output Screen
Related
So here's the situation. I want to build a Spotify-like button where the circular avatar is shown and on top of that, an icon button is been placed. I want to make the icon as much bigger to cover the whole avatar as possible but have failed after trying several answers already from this platform.
So, here's what I want. Center the IconButton in the avatar covering the whole size of the Circular Avatar. I'm attaching some screenshots as well as code. Have a look at it.
Thanks!
HERE's THE CODE
import 'package:flutter/material.dart';
class AddArtistWidget extends StatelessWidget {
const AddArtistWidget({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.topCenter,
children: [
const CircleAvatar(
backgroundColor: Colors.black26,
radius: 70,
),
IconButton(
padding: EdgeInsets.zero,
onPressed: () {},
icon: const Icon(
Icons.add,
size: 100,
color: Colors.white,
),
),
],
);
}
}
HERE's THE OUTPUT OF MY CODE
AND THAT's WHAT I WANT TO MAKE
Thanks again!
Stack( alignment: Alignment.topCenter,
children: [ const CircleAvatar( backgroundColor: Colors.black26, radius: 70, ),
IconButton( padding: EdgeInsets.zero, onPressed: () {},
icon: const Icon( Icons.add, size: 100,
color: Colors.white, ), ), ], );
replace this with
CircleAvatar(
backgroundColor: Colors.black26,
radius: 70,
child: GestureDetector(
onTap: () {},
child: const Icon(
Icons.add,
size: 100,
color: Colors.white,
),
),
),
I am trying to implement the below design
When I add the expandable floating button to the notch in bottom navigation bar it break the design of bottom navigation bar.
I tried AnchorOverlay but didn't help. Below is the code of my main screen where the expandable widget is notched in the bottom app bar
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: kPrimaryColor,
floatingActionButton: ExpandableFab(
distance: 112.0,
children: [
ActionButton(
onPressed: () {},
icon: const Icon(Icons.format_size),
),
ActionButton(
onPressed: () {},
icon: const Icon(Icons.insert_photo),
),
ActionButton(
onPressed: () {},
icon: const Icon(Icons.videocam),
),
],
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
//bottom navigation bar on scaffold
color: Colors.redAccent,
shape: const CircularNotchedRectangle(), //shape of notch
notchMargin:
5, //notche margin between floating button and bottom appbar
child: Row(
//children inside bottom appbar
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: const Icon(
Icons.menu,
color: Colors.white,
),
onPressed: () {},
),
IconButton(
icon: const Icon(
Icons.search,
color: Colors.white,
),
onPressed: () {},
),
IconButton(
icon: const Icon(
Icons.print,
color: Colors.white,
),
onPressed: () {},
),
IconButton(
icon: const Icon(
Icons.people,
color: Colors.white,
),
onPressed: () {},
),
],
),
),
);
}
Please refer this https://codewithandrea.com/articles/adding-animated-overlays-to-your-app/ maybe your issue will fixed.
When you use vscode and call Icon(Icons."the icon") to your code, the icon always showed up in the code line number section right (I don't about Android Studio). The scale icon that I called doesn't appear on the side, then when I hover my cursor, the scale image is broken. how do I fix it?
This is the code
import 'package:flutter/material.dart';
import 'package:project_ukk/constants/color_constant.dart';
import 'package:bubble_bottom_bar/bubble_bottom_bar.dart';
import 'package:project_ukk/pages/user_page/collection/collection_page.dart';
import 'package:project_ukk/pages/user_page/home/home_page.dart';
import 'package:project_ukk/pages/user_page/profile/profile_page.dart';
import 'package:project_ukk/pages/user_page/search/auction_page.dart';
class PageNavBar extends StatefulWidget {
const PageNavBar({Key? key}) : super(key: key);
#override
State<PageNavBar> createState() => _PageNavBarState();
}
class _PageNavBarState extends State<PageNavBar> {
int currentIndex = 0;
void changePage(int? index) {
setState(() {
currentIndex = index!;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
print('button pressed');
},
child: const Icon(
Icons.add,
size: 35,
),
backgroundColor: kRedColor,
),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
body: <Widget>[
HomePage(0),
AuctionPage(1),
CollectionPage(2),
ProfilePage(3),
][currentIndex],
bottomNavigationBar: BubbleBottomBar(
hasNotch: true,
fabLocation: BubbleBottomBarFabLocation.end,
opacity: 0.2,
currentIndex: currentIndex,
onTap: changePage,
borderRadius: const BorderRadius.vertical(
top: Radius.circular(16),
),
elevation: 8,
tilesPadding: const EdgeInsets.symmetric(vertical: 8.0),
items: const <BubbleBottomBarItem>[
BubbleBottomBarItem(
backgroundColor: kDarkBlue,
icon: Icon(
Icons.dashboard_outlined,
color: kBlackColor,
),
activeIcon: Icon(
Icons.dashboard_rounded,
color: kModerateCyan,
),
title: Text('Home'),
),
BubbleBottomBarItem(
backgroundColor: kDarkBlue,
icon: Icon(
Icons.scale_outlined,
color: kBlackColor,
),
activeIcon: Icon(
Icons.scale,
color: kPowderBlue,
),
title: Text('Logs'),
),
BubbleBottomBarItem(
backgroundColor: kDarkBlue,
icon: Icon(
Icons.collections_outlined,
color: kBlackColor,
),
activeIcon: Icon(
Icons.collections,
color: kLightRedColor,
),
title: Text('Logs'),
),
BubbleBottomBarItem(
backgroundColor: kDarkBlue,
icon: Icon(
Icons.person_outline,
color: kBlackColor,
),
activeIcon: Icon(
Icons.person,
color: kLightOrange,
),
title: Text('Logs'),
)
],
),
);
}
}
This problem is not related to Flutter or Dart in any way - that's the IDE issue you are using (it seems that you are using Visual Studio Code).
In fact, this is a known issue that is mentioned in the Flutter context here and globally here.
How to create a button that has text and an icon by using the latest button widget ElevatedButton.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Elevated Button',
home: FlutterExample(),
);
}
}
class FlutterExample extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Elevated Button with Icon and Text')),
body: Center(
child: ElevatedButton.icon(
icon: Icon(
Icons.home,
color: Colors.green,
size: 30.0,
),
label: Text('Elevated Button'),
onPressed: () {
print('Button Pressed');
},
style: ElevatedButton.styleFrom(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(20.0),
),
),
)));
}
}
you can add Row() or Wrap() Widget with multiple children in this case Icon() and Text()
ElevatedButton(
onPressed:() {},
child: Wrap(
children: <Widget>[
Icon(
Icons.favorite,
color: Colors.pink,
size: 24.0,
),
SizedBox(
width:10,
),
Text("Click me!", style:TextStyle(fontSize:20)),
],
),
),
You can use ElevatedButton.icon constructor:
ElevatedButton.icon(
onPressed: () {
//OnPressed Logic
},
icon: const Icon(Icons.plus_one),
label: const Text(
"Button Text"
)
),
You can use ElevatedButton.icon constructor for this like
ElevatedButton.icon(
icon: const Icon(Icons.add, size: 18),
label: Text('My elevated button'),
onPressed: () {},
),
I'm using an icon widget and I want that when I press on the icon to jump to another place (Like a call icon), and an option to open another widget when I press on the icon (like the three dots icon), my problem was that in the flutter icon widget there is no onlongpress...
any sample code that may help on doing that?
this is my code for now:
child: ListTile(
leading: CircleAvatar(
radius: 25.0,
backgroundColor: Colors.brown,
),
title: Text(helpRequest.category),
subtitle: Text(helpRequest.description),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: Icon(
Icons.call,
size: 20.0,
color: Colors.brown[900],
),
onPressed: () {
},
),
IconButton(
icon: Icon(
Icons.more_vert,
size: 20.0,
color: Colors.brown[900],
),
onPressed: () {
},
),
],
),
),
Instead of using IconButton, wrap the Icon with GestureDetector which will give you both onLongPress as well as onTap (onPressed). Please see the code below -
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text("Flutter Demo")),
body: MyStatefulWidget(),
),
);
}
}
class MyStatefulWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
Offset _tapPosition;
void _storePosition(TapDownDetails details) {
_tapPosition = details.globalPosition;
}
return ListTile(
leading: const CircleAvatar(
radius: 25.0,
backgroundColor: Colors.brown,
),
title: const Text("helpRequest.category"),
subtitle: const Text("helpRequest.description"),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
GestureDetector(
onTap: () => print("Tap: call"),
onLongPress: () => print("Long Press: Call"),
child: Icon(
Icons.call,
size: 20.0,
color: Colors.brown[900],
),
),
GestureDetector(
onTap: () => print("Tap: more_vert"),
onTapDown: _storePosition,
onLongPress: () async {
final RenderBox overlay =
Overlay.of(context).context.findRenderObject();
final int _selected = await showMenu(
items: [
PopupMenuItem(
value: 1,
child: Row(
children: <Widget>[
const Icon(Icons.delete),
const Text("Delete"),
],
),
),
PopupMenuItem(
value: 2,
child: Row(
children: <Widget>[
const Icon(Icons.edit),
const Text("Edit"),
],
),
)
],
context: context,
position: RelativeRect.fromRect(
_tapPosition &
const Size(40, 40), // smaller rect, the touch area
Offset.zero & overlay.size // Bigger rect, the entire screen
),
);
switch (_selected) {
case 1:
print("delete seleted");
break;
case 2:
print("edit seleted");
break;
}
},
child: Icon(
Icons.more_vert,
size: 20.0,
color: Colors.brown[900],
),
),
],
),
);
}
}