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

时间:2020-10-30 20:49:33

标签: flutter soundcloud

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

喜欢这张图片Example

(较暗的行)。

谢谢!

2 个答案:

答案 0 :(得分:0)

Expanded Widget应该可以解决您的问题。视频和文档位于链接上。它应允许将一行放置/推入屏幕底部,使其位于导航栏“上方”。只需用扩展的窗口小部件包裹您的窗口小部件即可。

答案 1 :(得分:0)

您可以使用名为persistentFooterButtons的Scaffold属性,并且可以向其添加小部件,这是应用https://i.stack.imgur.com/Tb4iA.jpg的图像,这是制作该应用的代码。 / p>

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