封闭路线后如何跳至综合浏览量的第二页?扑朔迷离

时间:2019-06-17 15:48:29

标签: flutter

在关闭所调用的路线后,我没有跳到第二页。我没有成功使用回调,因为我关闭的小部件 不是Pageview控件的一部分,当然我不知道如何使用回调。


第一堂课是具有底部应用栏和Pageview控制器的父级

BufferedInputStream

将首页分类为综合浏览量索引的第一页

read(buffer,offset,len)

secondsecondepage类是第二个页面浏览量索引,在关闭其他页面后我要跳转

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

  @override
  _MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  PageController _pageController;
  int _page = 0;
  Color _appBarColor =  Colors.pink;
  String _title = "MyApp";

  void navigateToPage(int page) {
    _pageController.animateToPage(page,
        duration: Duration(milliseconds: 300), curve: Curves.ease);
  }

  void onPageChanged(int page,) {
    String _temptitle = "";
    Color _tempColor;
    switch (page) {
      case 0:
        _temptitle = "page1";
        _tempColor =  Colors.pink;
        break;
      case 1:
        _temptitle = "page2";
        _tempColor = Colors.lightBlue;
        break;

    }
    setState(() {
      this._page = page;
      this._title = _temptitle;
      this._appBarColor = _tempColor;
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _pageController = new PageController();

  }

  @override
  Widget build(BuildContext context) {
    return  Scaffold(
      body: Stack(
          children: <Widget>[
            PageView(
                children: <Widget>[
                  firstpage(),
                  secondpage()
                ],
    controller: _pageController,
    onPageChanged: onPageChanged,
            )
          ]
      ),



      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.dashboard),
            backgroundColor:   Colors.pink,
            title: Text("page1"),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.calendar_today),
            backgroundColor: Colors.lightBlue,
            title: Text("page2"),
          ),


        ],
        onTap: navigateToPage,
        currentIndex: _page,
      ),


    );
  }
}

在其他页面上我可以打开的页面,关闭后我搜索跳到页面视图的第二个索引

class firstpage extends StatefulWidget {
  @override
  _firstpageState createState() => _firstpageState();
}

class _firstpageState extends State<firstpage> {
  @override
  Widget build(BuildContext context) {
    return new Center (
        child :new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
           new Text("page1"),

            new RaisedButton(
                child : new Text("jump to the otherpage"),
                onPressed :(){
            Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => otherpage()),
            );

            }
            )
          ],
        ));
  }
}

enter image description here

0 个答案:

没有答案