Flutter - 在底部导航栏上方添加一行

4
我想知道如何添加一行,点击后会像底部导航栏上方的底部表格一样运行。

就像这张图片示例

(较暗的那一行)。

谢谢!


你能添加一些你已经尝试过的代码片段或者你已经做过的研究吗? - yusufpats
2个回答

8

你可以使用名为persistentFooterButtons的Scaffold属性,并向其中添加一个小部件,这是该应用程序的图片https://istack.dev59.com/Tb4iA.webp,以下是制作该应用程序的代码。

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,
        ),
      ),
    );
  }
}

0

一个扩展小部件应该能解决你的问题。视频和文档在链接中。它应该允许将一行放置/推到屏幕底部,以便它位于导航栏的上方。只需用扩展小部件包装你的小部件即可。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接