Flutter —— 路由

turboksFlutter90

1. pubspec.yaml

fluro: ^1.5.1 #路由


2. 路由管理中心


    

// ignore: import_of_legacy_library_into_null_safe

import 'package:fluro/fluro.dart';

import 'package:ks/pages/category/catedetail.dart';

import 'package:ks/tabbar.dart';

import 'package:ks/pages/login/login.dart';

import 'package:ks/not_found.dart';

import 'package:ks/register.dart';


class Routes {

  static String home = '/';

  static String login = '/login';

  static String roomDetail = '/room/:roomId';

  static String register = '/register';

  static String catedetail = '/catedetail/:cateid/:typeid';


  static Handler _homeHandler = Handler(handlerFunc: (context, parameters) {

    return HomePage();

  });

  static Handler _loginHandler = Handler(handlerFunc: (context, parameters) {

    return LoginPage();

  });

  static Handler _notFoundHandler = Handler(handlerFunc: (context, parameters) {

    return NotFoundPage();

  });

  static Handler _registerHandler = Handler(handlerFunc: (context, parameters) {

    return RegisterPage();

  });


  static Handler _cateDetalHandler =

      Handler(handlerFunc: (context, parameters) {

    String? cid = parameters["cateid"]?.first;

    String? tid = parameters["typeid"]?.first;

    return CateDetailPage(cateid: cid.toString(), typeid: tid.toString());

  });


  static void configureRoutes(FluroRouter router) {

    router.define(home, handler: _homeHandler);

    router.define(login, handler: _loginHandler);

    router.notFoundHandler = _notFoundHandler;

    router.define(register, handler: _registerHandler);

    router.define(catedetail, handler: _cateDetalHandler);

  }

}

3. 路由的使用

              onPressed: () {

                Navigator.pushNamed(context, '/room/001002');

              },





相关文章

Flutter —— TabBarView每次进入都刷新?

Flutter —— TabBarView每次进入都刷新?

import 'package:flutter/material.dart';class PageOne extends StatefulWidget {const PageOne({...

Flutter —— 轮播图

Flutter —— 轮播图

1.pubspec.yaml  flutter_swiper: ^1.1.6 # 轮播图2.自定义一个类import 'package:flutter/material.dart&#...

Flutter —— 原生交互

Flutter —— 原生交互

一:传递数据flutter:var methodChannel = const MethodChannel("ksapp");onPressed: () {// sendToAnd...

Flutter —— 使用RGB颜色

Flutter —— 使用RGB颜色

import 'dart:ui';extension HexColor on Color {  /// String is in the format "aabbc...

Flutter —— 网络请求

Flutter —— 网络请求

1.pubspec.yamldio: ^3.0.9 #网络请求2.使用    var url = "urlurlurlurlurl";   ...

Flutter —— 左右切换视图

Flutter —— 左右切换视图

import 'package:flutter/material.dart';import 'package:ks/pageone.dart';import '...