我想在我的项目中包括一个底部导航栏,它包含在一个容器中,我已经给了它一定的高度和宽度。但我得到“底部溢出的像素Flutter”在底部时,我运行的程序。我已经包含了resizeToAvoidBottomInset: false,
,但它不工作,这是我的代码
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)
// ),
// ],
// );
}
}
这里是主区, dart
import 'package:flutter/material.dart';
// ignore: unused_import
import 'reusable/export.dart';
void main() => runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyHome(),
));
class MyHome extends StatefulWidget {
const MyHome({super.key});
@override
State<MyHome> createState() => _MyHomeState();
}
class _MyHomeState extends State<MyHome> {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
title: const Text(
'Kikuubo Online',
),
centerTitle: true,
),
body: const Padding(
padding: EdgeInsets.fromLTRB(16.0,10,0,0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBoxes(),
SearchPage(),
SizedBoxes(),
//include text
Text('All categories',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontSize: 20,
),
),
ListBar(),
SizedBoxes(),
ContainerPage(),
SizedBoxes(),
FilterDart(),
SizedBoxes(),
BottomPage(),
],
),
),
),
);
}
}
4条答案
按热度按时间kiayqfof1#
好吧,从你的代码的要点,我得到的想法,你是开始Flutter或一个总的新手。
这里我修正了你的代码,Icon不会在ontap方法中,你还有很多要学。
tzxcd3kk2#
你的代码有问题。您已在GestureDetector的onTap中声明了图标,但应将其声明为GestureDetector的子项。将bottomNavigationBar替换为:-
bgtovc5b3#
只需将
const Icon(Icons.home)
放入GestureDetector
的子参数。更新您的代码:
uwopmtnx4#
尝试使用
BottomNavigationBar
,并将此BottomNavigation
类指定为启动屏幕后的着陆类/页面希望这有帮助