123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import 'dart:convert';
- import 'package:fluro/fluro.dart';
- import 'package:flutter/material.dart';
- import 'package:sport/bean/forum.dart';
- import 'package:sport/bean/game.dart';
- import 'package:sport/bean/post.dart';
- import 'package:sport/bean/post_user.dart';
- import 'package:sport/bean/user.dart';
- import 'package:sport/pages/social/user_detail_page.dart';
- import '../application.dart';
- import 'routes.dart';
- typedef PageCreate = Future<List> Function(int pageNum);
- class NavigatorUtil {
- static Future<dynamic> _navigateTo(BuildContext context, String path,
- {bool replace = false,
- bool clearStack = false,
- Duration transitionDuration = const Duration(milliseconds: 250),
- RouteTransitionsBuilder? transitionBuilder}) {
- if (Application.router != null)
- return Application.router!.navigateTo(context, path,
- replace: replace,
- clearStack: clearStack,
- transitionDuration: transitionDuration,
- transitionBuilder: transitionBuilder,
- transition: TransitionType.material);
- return Future.value(false);
- }
- static String toJson(Object value) {
- if (value == null) return "";
- return Uri.encodeComponent(json.encode(value));
- }
- static Future goPage(BuildContext context, WidgetBuilder builder, {RouteSettings? settings}) {
- return Navigator.push(context, MaterialPageRoute(builder: builder, settings: settings));
- }
- static Future goPageRemoveUntil(BuildContext context, WidgetBuilder builder, {RouteSettings? settings}) {
- return Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: builder, settings: settings), (route) {
- if(route.settings.name == settings?.name)
- return false;
- return true;
- });
- // Navigator.replace(context, oldRoute: MaterialPageRoute(builder: builder, settings: settings), newRoute: MaterialPageRoute(builder: builder, settings: settings));
- }
- static Future goTransparentPage(BuildContext context, RoutePageBuilder pageBuilder, {RouteSettings? settings}) {
- return Navigator.push(context, PageRouteBuilder(pageBuilder: pageBuilder, settings: settings, opaque: false));
- }
- static Future pushAndRemoveUntil(BuildContext context, WidgetBuilder builder, RouteSettings? settings) {
- return Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: builder, settings: settings), (check) {
- if (check.settings.name == "/") return true;
- return false;
- });
- }
- ///跳转 uri: Routes.any
- static Future go(BuildContext context, String uri) {
- return _navigateTo(context, uri);
- }
- /// 首页
- static void goHomePage(BuildContext context) {
- _navigateTo(context, Routes.home, clearStack: true);
- }
- /// social detail
- static void goSocialDetail(BuildContext context, Forum forum) {
- _navigateTo(context, "${Routes.socialDetail}?data=${toJson(forum)}");
- }
- /// social post detail
- static void goSocialPostDetail(BuildContext context, Post post, {bool comment = false}) {
- _navigateTo(context, "${Routes.socialPostDetail}?data=${toJson(post)}&comment=$comment");
- }
- /// social user detail
- static Future goSocialUserDetail(BuildContext context, PostUser user) {
- return NavigatorUtil.goTransparentPage(context, (context,_,__) => UserDetailPage(user));
- // return _navigateTo(context, "${Routes.socialUserDetail}?data=${toJson(user)}");
- }
- static Future<dynamic> goGameDetails(BuildContext context, {required GameInfoData details}) {
- return _navigateTo(context, "${Routes.gameDetails}?details=${toJson(details)}");
- }
- static void goGameHistory(BuildContext context, GameInfoData details) {
- _navigateTo(context, "${Routes.sportHistory}?details=${toJson(details)}");
- }
- static void goRankPeopleDetails(BuildContext context, {required User details}) {
- _navigateTo(context, "${Routes.rankPeopleDetails}?details=${toJson(details)}");
- }
- static void goLogin(BuildContext context, {int type = 1}) {
- _navigateTo(context, "${Routes.login}?type=$type", clearStack: true);
- }
- static void goLicense(BuildContext context) {
- _navigateTo(context, "${Routes.license}");
- }
- static void goAuthCode(BuildContext context, {required String phone}) {
- _navigateTo(context, "${Routes.authCode}?phone=$phone");
- }
- static void goRegister(BuildContext context) {
- _navigateTo(context, "${Routes.register}");
- }
- static void goBasicInfo(BuildContext context, {required String username}) {
- _navigateTo(context, "${Routes.basicInfo}?username=${username.isNotEmpty == true ? Uri.encodeComponent(username) : ""}");
- }
- static void goFindPassword(BuildContext context) {
- _navigateTo(context, "${Routes.findPassword}");
- }
- static void goAchievementDetails(BuildContext context, {required int id, int userId = 0, bool replace = false}) {
- _navigateTo(context, "${Routes.achievementDetail}?id=$id&userId=$userId", replace: replace);
- }
- static void goLevel(BuildContext context) {
- _navigateTo(context, Routes.level);
- }
- // goback
- // static void goBack(){
- // _navigateTo.pop(context);
- // }
- }
|