<address id="r9vd9"><address id="r9vd9"><listing id="r9vd9"></listing></address></address>

      歡迎您光臨深圳塔燈網絡科技有限公司!
      電話圖標 余先生:13699882642

      網站百科

      為您解碼網站建設的點點滴滴

      flutter頁面間跳轉和銷毀

      發表日期:2018-11 文章編輯:小燈 瀏覽次數:10934

      flutter頁面間的跳轉有兩種方式,一種動態構建路由的方式,一種提前命名路由的方式。

      構建路由方式

      push方法:直接跳轉到下個頁面,可以傳遞參數

      Navigator.of(context).push(

      ? ? new MaterialPageRoute(builder: (BuildContext context) {

      //TextWdigetPage要跳轉的頁面

      //title要傳遞的參數

      ? ? ? return TextWdigetPage(title: "傳遞的參數");

      ? ? }))

      ),

      或者

      Navigator.push(context,

      ? ? new MaterialPageRoute(builder: (BuildContext context) {

      ? ? ? return TextWdigetPage(title: "傳遞的參數");

      ? ? })

      )

      pushAndRemoveUntil方式:跳轉到下個頁面,并且銷毀當前頁面

      //第一個小菜理解為上下文環境,

      // 第二個參數為靜態注冊的對應的頁面名稱,

      // 第三個參數為跳轉后的操作,route == null 為銷毀當前頁面

      Navigator.pushAndRemoveUntil(context,

      ? ? new MaterialPageRoute(builder: (BuildContext context) {

      ? ? ? return TextWdigetPage(title: "傳遞的參數");

      ? ? }), (route) => route == null

      )

      提前命名路由

      不能傳遞參數,只能在mian.dart里面寫死要跳轉的路由協議

      @override

      Widget build(BuildContext context) {

      ? return MaterialApp(

      ? ? title: "flutter學習",

      ? ? home: Scaffold(

      ? ? ? appBar: AppBar(title: Text("flutter學習"),),

      ? ? ? body: ListView.builder(

      ? ? ? ? ? itemCount: list.length,

      ? ? ? ? ? itemBuilder: (context, position) {

      ? ? ? ? ? ? return HomeListItem(position, list[position], (index) =>

      ? ? ? ? ? ? ? ? Navigator.push(context,

      ? ? ? ? ? ? ? ? ? ? new MaterialPageRoute(builder: (BuildContext context) {

      ? ? ? ? ? ? ? ? ? ? ? return pageList[index];

      ? ? ? ? ? ? ? ? ? ? }))

      ? ? ? ? ? ? );

      ? ? ? ? ? }),

      ? ? ),

      ? ? //不能傳遞參數,必須在main里面注冊

      ? ? routes: {

      ? ? ? "listview_builder_page": (BuildContext context) =>

      ? ? ? new ListView_Builder_Page(),

      ? ? ? "listview_separated_page": (BuildContext context) =>

      ? ? ? new ListView_Separated_Page(),

      ? ? },

      ? );

      }

      調用時可以用以下方式:

      Navigator.pushNamed(context, "listview_builder_page")

      或者

      Navigator.pushNamedAndRemoveUntil(

      ? ? context, "listview_builder_page", (router) => router == null)

      ),

      頁面的銷毀:

      //構建路由

      //一個參數,為上下文環境,銷毀當前頁面

      Navigator.pop(context);

      //一個參數,第一個為上下文環境,第二個為要攜帶的參數,銷毀當前頁面

      Navigator.pop(context, "攜帶參數");

      //命名路由

      Navigator.popAndPushNamed(context, 'listview_builder_page');

      接收路由返回的參數:

      //構建路由

      Navigator.push(context,

      ? ? new MaterialPageRoute(builder: (BuildContext context) {

      ? ? ? return TextWdigetPage(title: "傳遞的參數");

      ? ? })

      ).then((Object result) {

      ? ??? print("返回值:${result.toString()}");

      })

      Navigator.pushAndRemoveUntil(context,

      ? ? new MaterialPageRoute(builder: (BuildContext context) {

      ? ? ? return TextWdigetPage(title: "傳遞的參數");

      ? ? }), (route) => route == null

      ).then((Object result) {

      ???? print("返回值:${result.toString()}");

      })

      命名路由

      Navigator.pushNamed(context, "listview_builder_page").then((Object result) {

      ?????? print("返回值:${result.toString()}");

      })



      練習demo,鏈接https://gitee.com/xgljh/Flutter


      本頁內容由塔燈網絡科技有限公司通過網絡收集編輯所得,所有資料僅供用戶學習參考,本站不擁有所有權,如您認為本網頁中由涉嫌抄襲的內容,請及時與我們聯系,并提供相關證據,工作人員會在5工作日內聯系您,一經查實,本站立刻刪除侵權內容。本文鏈接:http://www.webpost.com.cn/17571.html
      相關APP開發
       八年  行業經驗

      多一份參考,總有益處

      聯系深圳網站公司塔燈網絡,免費獲得網站建設方案及報價

      咨詢相關問題或預約面談,可以通過以下方式與我們聯系

      業務熱線:余經理:13699882642

      Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.    

      国产成人精品综合在线观看