其他分享
首页 > 其他分享> > Flutter路由

Flutter路由

作者:互联网

initialRoute:'/',  //初始化加载的路由

debugShowCheckedModeBanner: false, //去掉debug图片

 

先引入需要跳转的页面

 

在Scaffold里 floatingActionButton  浮动按钮

Navigator.pop返回上一级

命名路由

在main.dart里MaterialApp配置routes (''/方法:(context)=>哪个页面),

Navigator.pushNamed(context,'/router 名字');

命名路由传值:

 

       onGenerateRoute: (RouteSettings settings) {
          final String name = settings.name;
          final Function pageContentBuilder = this.routes[name];
          if (pageContentBuilder != null) {
            if (settings.arguments != null) {
              final Route route = MaterialPageRoute(
                  builder: (context) => pageContentBuilder(context,
                      arguments: settings.arguments));
              return route;
            } else {
              final Route route = MaterialPageRoute(
                  builder: (context) => pageContentBuilder(context));
              return route;
            }
          }
        }

有状态组件接收值

路由替换,返回根路由

返回根路由

AppBar

自定义导航

TabBar

属性

TabController

import 'package:flutter/material.dart';

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

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

class _TabBarConState extends State<TabBarCon>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  @override
  void initState() {
    super.initState();
    _tabController = new TabController(length: 2, vsync: this);
    _tabController.addListener(() {
      print(_tabController.index);
    });
  }

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Text('TabBarControllerpage'),
          bottom: TabBar(
            controller: this._tabController,
            tabs: <Widget>[
              Tab(text: '推荐'),
              Tab(text: '热映'),
            ],
          )),
      body: TabBarView(
        controller: this._tabController,
        children: <Widget>[
          Center(child: Text('1111')),
          Center(child: Text('1111'))
        ],
      ),
    );
  }
}

 

标签:settings,tabController,final,context,pageContentBuilder,Flutter,路由
来源: https://blog.csdn.net/gw616/article/details/112618197