【问题标题】:How can I add navigation routes to flutter bottom navigation routes如何将导航路线添加到颤振底部导航路线
【发布时间】:2019-09-30 11:22:35
【问题描述】:

这是我迄今为止编辑的代码。

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;

  static const TextStyle optionStyle =
      TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
  static const List<Widget> _widgetOptions = <Widget>[

我想知道如何在这个区域内添加导航路线 文本( '索引 0:主页', 风格:选项风格, ), 文本( '索引 1:商业', 风格:选项风格, ), 文本( '索引 2:学校', 风格:选项风格, ), ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('BottomNavigationBar Sample'),
      ),
      body: Center(
        child: _widgetOptions.elementAt(_selectedIndex),
      ),
      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,
      ),
    );
  }
}

这是我迄今为止编辑的代码。

【问题讨论】:

    标签: flutter routes tabs navigation android-bottomappbar


    【解决方案1】:

    _widgetOptions 是一个数组,其中包含对每个底部导航项的内容的引用。
    在此处创建您的页面。就是这样

    final List<Widget> _widgetOptions = [
        Home(),      
        Business(),
        School(),
      ];
    

    【讨论】:

    • 将其标记为将来访问您问题的人的答案
    猜你喜欢
    • 1970-01-01
    • 2019-06-30
    • 2022-11-25
    • 2021-10-24
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    相关资源
    最近更新 更多