【问题标题】:Flutter - Add a Row above Bottom Navigation BarFlutter - 在底部导航栏上方添加一行
【发布时间】:2021-02-13 08:11:36
【问题描述】:

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

喜欢这张图片Example

(较暗的行)。

谢谢!

【问题讨论】:

  • 能否添加一些你尝试过的代码sn-ps或者你已经做过的一些研究

标签: flutter soundcloud


【解决方案1】:

您可以使用名为persistentFooterButtons 的 Scaffold 属性,并且可以向其添加一个小部件,这是应用程序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,
        ),
      ),
    );
  }
}

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-07
      相关资源
      最近更新 更多