Flutter - 在底部导航栏上方添加一行
Flutter - Add a Row above Bottom Navigation Bar
我想知道如何添加一行,点击后其功能类似于底部导航栏上方的底部 Sheet。
喜欢这张图片Example
(较暗的行)。
谢谢!
Expanded Widget 应该可以解决您的问题。视频和文档位于 link。它应该允许一行 placed/pushed 到屏幕底部,以便它位于导航栏的“上方”。只需用扩展小部件包装您的小部件。
你可以使用一个名为 persistentFooterButtons
的脚手架 属性,你可以向它添加一个小部件,这是应用程序的图像 https://i.stack.imgur.com/Tb4iA.jpg,这是代码用于制作应用程序。
void main() async {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Home',
style: optionStyle,
),
Text(
'Index 1: Business',
style: optionStyle,
),
Text(
'Index 2: School',
style: optionStyle,
),
];
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
color: Colors.white,
),
===================这就是你所需要的===================== =========
persistentFooterButtons: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
IconButton(
iconSize: 35,
icon: Icon(Icons.play_arrow),
onPressed: null,
),
Container(child: Text("Some data over hereSome data ")),
IconButton(
icon: Icon(Icons.favorite),
onPressed: null,
)
],
)
],
============================================= ====
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
title: Text('Business'),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
title: Text('School'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
),
);
}
}
我想知道如何添加一行,点击后其功能类似于底部导航栏上方的底部 Sheet。
喜欢这张图片Example
(较暗的行)。
谢谢!
Expanded Widget 应该可以解决您的问题。视频和文档位于 link。它应该允许一行 placed/pushed 到屏幕底部,以便它位于导航栏的“上方”。只需用扩展小部件包装您的小部件。
你可以使用一个名为 persistentFooterButtons
的脚手架 属性,你可以向它添加一个小部件,这是应用程序的图像 https://i.stack.imgur.com/Tb4iA.jpg,这是代码用于制作应用程序。
void main() async {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Home',
style: optionStyle,
),
Text(
'Index 1: Business',
style: optionStyle,
),
Text(
'Index 2: School',
style: optionStyle,
),
];
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
color: Colors.white,
),
===================这就是你所需要的===================== =========
persistentFooterButtons: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
IconButton(
iconSize: 35,
icon: Icon(Icons.play_arrow),
onPressed: null,
),
Container(child: Text("Some data over hereSome data ")),
IconButton(
icon: Icon(Icons.favorite),
onPressed: null,
)
],
)
],
============================================= ====
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
title: Text('Business'),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
title: Text('School'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
),
);
}
}