如何从底部导航栏项目打开其他 .dart activity?

How do i open other .dart activity from bottom navigation bar item?

我用 flutter 实现了下面的底部导航栏

import 'package:flutter/material.dart';

class Test extends StatelessWidget  {
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
    bottomNavigationBar: new BottomNavigationBar(
        items: [
          new BottomNavigationBarItem(
              icon: new Icon(Icons.add),
              title: new Text("trends")
          ),
          new BottomNavigationBarItem(
              icon: new Icon(Icons.location_on),
              title: new Text("feed")
          ),
          new BottomNavigationBarItem(
              icon: new Icon(Icons.people),
              title: new Text("community")
          )
        ]
    )
);}}

如何让 onTap 在每个 BottomNavigationBar 项目上打开新的 .dart class? 我已尝试使用选项卡的 TabBarView,但不知道如何处理底部导航栏。

你可以这样做

import 'package:flutter/material.dart';

class Test extends StatefulWidget {
  @override
  TestState createState() {
    return new TestState();
  }
}

class TestState extends State<Test> {
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      bottomNavigationBar: new BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (newIndex) => setState((){_currentIndex = newIndex;}),
        items: [
          new BottomNavigationBarItem(
              icon: new Icon(Icons.add),
              title: new Text("trends")
          ),
          new BottomNavigationBarItem(
              icon: new Icon(Icons.location_on),
              title: new Text("feed")
          ),
          new BottomNavigationBarItem(
              icon: new Icon(Icons.people),
              title: new Text("community")
          ),
        ],
      ),
      body: new IndexedStack(
        index: _currentIndex,
        children: <Widget>[
          new YourCustomTrendsWidget(),
          new YourCustomFeedWidget(),
          new YourCustomCommunityWidget(),
        ],
      ),
    );
  }
}