navigator_utils.dart 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. import 'package:deus_app/page/login/login_page.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. /**
  5. * 导航栏
  6. * Created by guoshuyu
  7. * Date: 2018-07-16
  8. */
  9. class NavigatorUtils {
  10. ///替换
  11. static pushReplacementNamed(BuildContext context, String routeName) {
  12. Navigator.pushReplacementNamed(context, routeName);
  13. // if (navigator == null) {
  14. // try {
  15. // navigator = Navigator.of(context);
  16. // } catch (e) {
  17. // error = true;
  18. // }
  19. // }
  20. //
  21. // if (replace) {
  22. // ///如果可以返回,清空开始,然后塞入
  23. // if (!error && navigator.canPop()) {
  24. // navigator.pushAndRemoveUntil(
  25. // router,
  26. // ModalRoute.withName('/'),
  27. // );
  28. // } else {
  29. // ///如果不可返回,直接替换当前
  30. // navigator.pushReplacement(router);
  31. // }
  32. // } else {
  33. // navigator.push(router);
  34. // }
  35. }
  36. ///切换无参数页面
  37. static pushNamed(BuildContext context, String routeName) {
  38. Navigator.pushNamed(context, routeName);
  39. }
  40. // ///主页
  41. // static goHome(BuildContext context) {
  42. // Navigator.pushReplacementNamed(context, HomePage.sName);
  43. // }
  44. ///登录页
  45. static goLogin(BuildContext context) {
  46. Navigator.pushReplacementNamed(context, LoginPage.sName);
  47. }
  48. // ///图片预览
  49. // static gotoPhotoViewPage(BuildContext context, String? url) {
  50. // Navigator.pushNamed(context, PhotoViewPage.sName, arguments: url);
  51. // }
  52. //
  53. // ///个人中心
  54. // static goPerson(BuildContext context, String? userName) {
  55. // NavigatorRouter(context, new PersonPage(userName));
  56. // }
  57. //
  58. // ///请求数据调试页面
  59. // static goDebugDataPage(BuildContext context) {
  60. // return NavigatorRouter(context, new DebugDataPage());
  61. // }
  62. // ///仓库详情
  63. // static Future goReposDetail(
  64. // BuildContext context, String? userName, String? reposName) {
  65. // ///利用 SizeRoute 动画大小打开
  66. // return Navigator.push(
  67. // context,
  68. // PageRouteBuilder(
  69. // pageBuilder: (context, animation, secondaryAnimation) =>
  70. // RepositoryDetailPage(userName, reposName),
  71. // transitionsBuilder: (context, animation, secondaryAnimation, child) {
  72. // double begin = 0;
  73. // double end = 1;
  74. // var curve = Curves.ease;
  75. //
  76. // var tween =
  77. // Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
  78. //
  79. // return Align(
  80. // child: SizeTransition(
  81. // sizeFactor: animation.drive(tween),
  82. // child: NeverOverScrollIndicator(
  83. // needOverload: false,
  84. // child: child,
  85. // ),
  86. // ),
  87. // );
  88. // },
  89. // ));
  90. // }
  91. //
  92. // ///荣耀列表
  93. // static Future goHonorListPage(BuildContext context, List? list) {
  94. // return Navigator.push(
  95. // context,
  96. // PageRouteBuilder(
  97. // pageBuilder: (context, animation, secondaryAnimation) =>
  98. // HonorListPage(list),
  99. // transitionsBuilder: (context, animation, secondaryAnimation, child) {
  100. // double begin = 0;
  101. // double end = 1;
  102. // var curve = Curves.ease;
  103. //
  104. // var tween =
  105. // Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
  106. //
  107. // return Align(
  108. // child: SizeTransition(
  109. // sizeFactor: animation.drive(tween),
  110. // child: NeverOverScrollIndicator(
  111. // needOverload: false,
  112. // child: child,
  113. // ),
  114. // ),
  115. // );
  116. // },
  117. // ),
  118. // );
  119. // }
  120. //
  121. // ///仓库版本列表
  122. // static Future goReleasePage(BuildContext context, String? userName,
  123. // String? reposName, String releaseUrl, String tagUrl) {
  124. // return NavigatorRouter(
  125. // context,
  126. // new ReleasePage(
  127. // userName,
  128. // reposName,
  129. // releaseUrl,
  130. // tagUrl,
  131. // ));
  132. // }
  133. //
  134. // ///issue详情
  135. // static Future goIssueDetail(
  136. // BuildContext context, String? userName, String? reposName, String num,
  137. // {bool needRightLocalIcon = false}) {
  138. // return NavigatorRouter(
  139. // context,
  140. // new IssueDetailPage(
  141. // userName,
  142. // reposName,
  143. // num,
  144. // needHomeIcon: needRightLocalIcon,
  145. // ));
  146. // }
  147. //
  148. // ///通用列表
  149. // static gotoCommonList(
  150. // BuildContext context, String? title, String showType, CommonListDataType dataType,
  151. // {String? userName, String? reposName}) {
  152. // NavigatorRouter(
  153. // context,
  154. // new CommonListPage(
  155. // title,
  156. // showType,
  157. // dataType,
  158. // userName: userName,
  159. // reposName: reposName,
  160. // ));
  161. // }
  162. //
  163. // ///仓库详情通知
  164. // static Future goNotifyPage(BuildContext context) {
  165. // return NavigatorRouter(context, new NotifyPage());
  166. // }
  167. //
  168. // ///用户趋势
  169. // static Future goTrendUserPage(BuildContext context) {
  170. // return NavigatorRouter(context, new TrendUserPage());
  171. // }
  172. //
  173. // ///搜索
  174. // static Future goSearchPage(BuildContext context, Offset centerPosition) {
  175. // return showGeneralDialog(
  176. // context: context,
  177. // pageBuilder: (BuildContext buildContext, Animation<double> animation,
  178. // Animation<double> secondaryAnimation) {
  179. // return Builder(builder: (BuildContext context) {
  180. // return pageContainer(SearchPage(centerPosition), context);
  181. // });
  182. // },
  183. // barrierDismissible: false,
  184. // barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
  185. // barrierColor: Color(0x01000000),
  186. // transitionDuration: const Duration(milliseconds: 150),
  187. // transitionBuilder: (BuildContext context, Animation<double> animation,
  188. // Animation<double> secondaryAnimation, Widget child) {
  189. // return FadeTransition(
  190. // opacity: CurvedAnimation(
  191. // parent: animation,
  192. // curve: Curves.easeOut,
  193. // ),
  194. // child: child,
  195. // );
  196. // },
  197. // );
  198. // }
  199. //
  200. // ///提交详情
  201. // static Future goPushDetailPage(BuildContext context, String? userName,
  202. // String? reposName, String? sha, bool needHomeIcon) {
  203. // return NavigatorRouter(
  204. // context,
  205. // new PushDetailPage(
  206. // sha,
  207. // userName,
  208. // reposName,
  209. // needHomeIcon: needHomeIcon,
  210. // ));
  211. // }
  212. //
  213. // ///全屏Web页面
  214. // static Future goGSYWebView(BuildContext context, String url, String? title) {
  215. // return NavigatorRouter(context, new GSYWebView(url, title));
  216. // }
  217. //
  218. // ///登陆Web页面
  219. // static Future goLoginWebView(BuildContext context, String url, String title) {
  220. // return NavigatorRouter(context, new LoginWebView(url, title));
  221. // }
  222. //
  223. // ///文件代码详情Web
  224. // static gotoCodeDetailPageWeb(BuildContext context,
  225. // {String? title,
  226. // String? userName,
  227. // String? reposName,
  228. // String? path,
  229. // String? data,
  230. // String? branch,
  231. // String? htmlUrl}) {
  232. // NavigatorRouter(
  233. // context,
  234. // new CodeDetailPageWeb(
  235. // title: title,
  236. // userName: userName,
  237. // reposName: reposName,
  238. // path: path,
  239. // data: data,
  240. // branch: branch,
  241. // htmlUrl: htmlUrl,
  242. // ));
  243. // }
  244. //
  245. // ///根据平台跳转文件代码详情Web
  246. // static gotoCodeDetailPlatform(BuildContext context,
  247. // {String? title,
  248. // String? userName,
  249. // String? reposName,
  250. // String? path,
  251. // String? data,
  252. // String? branch,
  253. // String? htmlUrl}) {
  254. // NavigatorUtils.gotoCodeDetailPageWeb(
  255. // context,
  256. // title: title,
  257. // reposName: reposName,
  258. // userName: userName,
  259. // data: data,
  260. // path: path,
  261. // branch: branch,
  262. // );
  263. // }
  264. //
  265. // ///用户配置
  266. // static gotoUserProfileInfo(BuildContext context) {
  267. // NavigatorRouter(context, new UserProfileInfo());
  268. // }
  269. //
  270. // ///公共打开方式
  271. // static NavigatorRouter(BuildContext context, Widget widget) {
  272. // return Navigator.push(
  273. // context,
  274. // new CupertinoPageRoute(
  275. // builder: (context) => pageContainer(widget, context)));
  276. // }
  277. //
  278. // ///Page页面的容器,做一次通用自定义
  279. // static Widget pageContainer(widget, BuildContext context) {
  280. // return MediaQuery(
  281. //
  282. // ///不受系统字体缩放影响
  283. // data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
  284. // child: NeverOverScrollIndicator(
  285. // needOverload: false,
  286. // child: widget,
  287. // ));
  288. // }
  289. //
  290. // ///弹出 dialog
  291. // static Future<T?> showGSYDialog<T>({
  292. // required BuildContext context,
  293. // bool barrierDismissible = true,
  294. // WidgetBuilder? builder,
  295. // }) {
  296. // return showDialog<T>(
  297. // context: context,
  298. // barrierDismissible: barrierDismissible,
  299. // builder: (context) {
  300. // return MediaQuery(
  301. //
  302. // ///不受系统字体缩放影响
  303. // data: MediaQueryData.fromView(WidgetsBinding.instance.platformDispatcher.views.first)
  304. // .copyWith(textScaleFactor: 1),
  305. // child: NeverOverScrollIndicator(
  306. // needOverload: false,
  307. // child: new SafeArea(child: builder!(context)),
  308. // ));
  309. // });
  310. // }
  311. }