路由
基礎方法
Get.toNamed("/NextScreen"); Get.offNamed("/NextScreen"); Get.offAllNamed("/NextScreen");
路由傳參
Get.toNamed("/NextScreen", arguments: 'Get is the best'); print(Get.arguments); //print out: Get is the best
命令路由
void main() { runApp( GetMaterialApp( initialRoute: '/', getPages: [ GetPage( name: '/', page: () => MyHomePage(), ), GetPage( name: '/profile/', page: () => MyProfile(), ), //你可以為有參數的路由定義一個不同的頁面,也可以為沒有參數的路由定義一個不同的頁面,但是你必須在不接收參數的路由上使用斜杠"/",就像上面說的那樣。 GetPage( name: '/profile/:user', page: () => UserProfile(), ), GetPage( name: '/third', page: () => Third(), transition: Transition.cupertino ), ], ) ); } // 跳轉路由 Get.toNamed("/second/34954"); // 獲取路由參數 print(Get.parameters['user']); // out: 34954
返回路由傳值
在購物車、訂單中很有用
// 導航到該路由,通過 await 獲取回調結果 var data = await Get.to(Payment()); if(data == 'success') madeAnything(); // 傳遞回調內容 Get.back(result: 'success');
免 context 導航
Snackbar
Get.snackbar('Hi', 'i am a modern snackbar');
也可以使用 Get.rawSnackbar()
Dialog
Get.dialog(YourDialogWidget()); Get.defaultDialog( onConfirm: () => print("Ok"), middleText: "Dialog made in 3 lines of code" ); // 還可以使用 Get.generalDialog 代替 showGeneralDialog
BottomSheet
Get.bottomSheet( Container( child: Wrap( children: <Widget>[ ListTile( leading: Icon(Icons.music_note), title: Text('Music'), onTap: () {} ), ListTile( leading: Icon(Icons.videocam), title: Text('Video'), onTap: () {}, ), ], ), ) );
2333