flutter - 带 flutter 的导航导轨

标签 flutter material-design flutter-layout flutter-navigation

Material 设计指南包括一个名为 Navigation rail 的组件。 .

如何使用 flutter 创建导航栏?

enter image description here

最佳答案

Flutter 1.17 的最新版本包含一个内置的 NavigationRail 组件。

什么是导航轨道?

The rail is a side navigation component that displays three to seven app destinations and, optionally, a Floating Action Button. Each destination is represented by an icon and a text label. The rail can function on its own at larger screen sizes, such as desktop and tablet. When users transition between screen sizes and devices, the rail can also complement other navigation components, such as bottom navigation.



例子
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: MyStatefulWidget(),
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  MyStatefulWidget({Key key}) : super(key: key);

  @override
  _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  int _selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Row(
        children: <Widget>[
          NavigationRail(
            selectedIndex: _selectedIndex,
            onDestinationSelected: (int index) {
              setState(() {
                _selectedIndex = index;
              });
            },
            labelType: NavigationRailLabelType.selected,
            destinations: [
              NavigationRailDestination(
                icon: Icon(Icons.favorite_border),
                selectedIcon: Icon(Icons.favorite),
                label: Text('First'),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.bookmark_border),
                selectedIcon: Icon(Icons.book),
                label: Text('Second'),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.star_border),
                selectedIcon: Icon(Icons.star),
                label: Text('Third'),
              ),
            ],
          ),
          VerticalDivider(thickness: 1, width: 1),
          // This is the main content.
          Expanded(
            child: Center(
              child: Text('selectedIndex: $_selectedIndex'),
            ),
          )
        ],
      ),
    );
  }
}

查找现场演示 here .

Here是官方文档。

关于flutter - 带 flutter 的导航导轨,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61651542/

相关文章:

android - 调整 androidx.preference 对话框以跟随 Material You

java - 如何去除 Android Material Design 中 TextInputLayout 下的下划线?

flutter - flutter 中带有圆角的警报对话框

Flutter (Dart) : Split the screen into 6 sections, 每个在中心有一个角

flutter - 如何从 Streambuilder 订购项目

flutter - 如何从扫描的照片中选择文本?

flutter - flutter中已经存在项目位置

java - Google Inbox like RecyclerView 项目打开动画

dart - Dart/Flutter 列表中的左侧、右侧编译器错误

android - 在 flutter 应用程序中添加启动画面的正确方法是什么?