I want to include a bottomNavigation Bar in my project, It’s included in a container and I have given it a certain height and width. But I get "bottom overflowed by pixels flutter" at the bottom when I run the program.
I have included resizeToAvoidBottomInset: false,
but it’s not working
Here is my code
import 'package:flutter/material.dart';
import 'package:listview/pages/cart.dart';
class BottomPage extends StatefulWidget {
const BottomPage({super.key});
@override
State<BottomPage> createState() => _BottomPageState();
}
class _BottomPageState extends State<BottomPage> {
@override
Widget build(BuildContext context) {
// ignore: unused_local_variable
List pages = const [CartPage()];
// ignore: unused_local_variable
int index = 0;
// ignore: sized_box_for_whitespace
return SafeArea(
child: Scaffold(
resizeToAvoidBottomInset: false,
body: pages[index],
bottomNavigationBar: Container(
// height: 20,
// width: MediaQuery.sizeOf(context).width / 2,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
GestureDetector(
onTap: () {
setState(
() {
index = 0;
},
);
const Icon(Icons.home);
},
),
],
),
),
),
);
// BottomNavigationBar(
// items: const [
// BottomNavigationBarItem(
// label: "Home",
// icon: Icon(Icons.home)
// ),
// BottomNavigationBarItem(
// label: "settings",
// icon: Icon(Icons.settings)
// ),
// ],
// );
}
}
3
Answers
Well from the gist of your code, I get the idea that you are starting flutter or a total newbie in it.
Here I fixed your code, the Icon would not be inside the ontap method, and you have still a lot to learn.
Just put
const Icon(Icons.home)
into child parameter ofGestureDetector
.update your code:
There’s an issue in your code. You have declared the icon in onTap of GestureDetector but it should be declared as the child of it. Replace your bottomNavigationBar with :-