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

Ida*_*Ber 5 soundcloud flutter

我想知道如何添加一行,单击该行后将起到类似于底部导航栏上方的底部工作表的作用。

喜欢这个图片示例

(较暗的行)。

谢谢!

ahm*_*med 9

您可以使用名为 的 Scaffold 属性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,
        ),
Run Code Online (Sandbox Code Playgroud)

=================== 这就是您所需要的========================== ====

        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,
              )
            ],
          )
        ],
Run Code Online (Sandbox Code Playgroud)

===================================================

        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,
        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)