我从网上带来了一些用于不同appbar设计的代码,并将其应用于我的代码。我想为我的应用程序使用bottomnavigationbar和tabbar。但是,当我尝试将它们一起应用时,bottomenavigationbar的部分溢出了底部的无穷大像素。为了在tabbarview上进行滚动,我也附加了expand和singlechildscrollview,但是没有任何变化。 我是Dart和Flutter的真正初学者。 请给我提示以解决此问题。
Home.dart
class Home extends StatelessWidget {
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: Column(
children: <Widget>[
Container(
height: 160.0,
child: Stack(
children: <Widget>[
Container(
color: Colors.pinkAccent[400],
width: MediaQuery.of(context).size.width,
height: 100.0,
child: Center(
child: Text(
"여행 앱 로고",
style: TextStyle(color: Colors.white, fontSize: 18.0),
),
),
),
Positioned(
top: 80.0,
left: 0.0,
right: 0.0,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(1.0),
border: Border.all(
color: Colors.grey.withOpacity(0.5), width: 1.0),
color: Colors.white),
child: Row(
children: [
IconButton(
icon: Icon(
Icons.menu,
color: Colors.pinkAccent[400],
),
onPressed: () {
print("your menu action here");
_scaffoldKey.currentState.openDrawer();
},
),
Expanded(
child: TextField(
decoration: InputDecoration.collapsed(
hintText: "검색",
),
),
),
IconButton(
icon: Icon(
Icons.search,
color: Colors.pinkAccent[400],
),
onPressed: () {
print("your menu action here");
},
),
],
),
),
),
)
],
),
),
Container(
child: TabBarHome(),
),
],
),
);
}
}
TabBarHome.dart
class TabBarHome extends StatefulWidget {
@override
_TabBarHomeState createState() => _TabBarHomeState();
}
class _TabBarHomeState extends State<TabBarHome> with
SingleTickerProviderStateMixin {
TabController _tabController;
@override
void initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this);
}
@override
void dispose() {
super.dispose();
_tabController.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
Expanded(
child: SingleChildScrollView(
child: TabBarView(
controller: _tabController,
children: <Widget>[
Text('회원가입'),
Text('마이페이지'),
Text('공지'),
],
),
),
),
],
),
bottomNavigationBar: Container(
child: TabBar(
controller: _tabController,
labelColor: Colors.black45,
tabs: <Widget>[
Tab(icon: Icon(Icons.person), text: '회원가입'),
Tab(icon: Icon(Icons.assignment_ind), text: '마이페이지'),
Tab(icon: Icon(Icons.list), text: '공지'),
],
),
color: Colors.cyanAccent[100],
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: FloatingActionButton.extended(
onPressed: () { },
tooltip: '해외 명소',
icon: Icon(Icons.location_on),
label: Text("해외"),
backgroundColor: Colors.orange[600],
elevation: 10.0,
),
);
}
}
我希望滚动每个tabbarview页面,并且不会出错。谢谢。
答案 0 :(得分:0)
这是我为您解决的问题。我也只用了一个脚手架,而不是两个。请检查一下,让我知道它是否适合您。
class Home extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _HomeState();
}
}
class _HomeState extends State<Home> with TickerProviderStateMixin {
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
TabController _tabController;
int _selectedTabIndex;
@override
void initState() {
super.initState();
_selectedTabIndex = 0;
_tabController = TabController(length: 3, vsync: this);
}
@override
void dispose() {
super.dispose();
_tabController.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: Column(
children: <Widget>[
Container(
height: 160.0,
child: Stack(
children: <Widget>[
Container(
color: Colors.pinkAccent[400],
width: MediaQuery.of(context).size.width,
height: 100.0,
child: Center(
child: Text(
"여행 앱 로고",
style: TextStyle(color: Colors.white, fontSize: 18.0),
),
),
),
Positioned(
top: 80.0,
left: 0.0,
right: 0.0,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(1.0),
border: Border.all(
color: Colors.grey.withOpacity(0.5), width: 1.0),
color: Colors.white),
child: Row(
children: [
IconButton(
icon: Icon(
Icons.menu,
color: Colors.pinkAccent[400],
),
onPressed: () {
print("your menu action here");
_scaffoldKey.currentState.openDrawer();
},
),
Expanded(
child: TextField(
decoration: InputDecoration.collapsed(
hintText: "검색",
),
),
),
IconButton(
icon: Icon(
Icons.search,
color: Colors.pinkAccent[400],
),
onPressed: () {
print("your menu action here");
},
),
],
),
),
),
)
],
),
),
Expanded(
child: TabBarView(
controller: _tabController,
children: <Widget>[
Text('회원가입'),
Text('마이페이지'),
Text('공지'),
],
),
)
/* Container(
child: TabBarHome(),
),*/
],
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedTabIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.person), title: Text('회원가입')),
BottomNavigationBarItem(
icon: Icon(Icons.assignment_ind), title: Text('마이페이지')),
BottomNavigationBarItem(icon: Icon(Icons.list), title: Text('공지')),
],
onTap: (int tappedIndex) {
setState(() {
_selectedTabIndex = tappedIndex;
_tabController.index = tappedIndex;
});
},
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: FloatingActionButton.extended(
onPressed: () {},
tooltip: '해외 명소',
icon: Icon(Icons.location_on),
label: Text("해외"),
backgroundColor: Colors.orange[600],
elevation: 10.0,
),
);
}
}