Bili bilibili case study framework building

fluro jump route Library

Introduce:

dependencies:
  fluro: "^1.4.0"

Initialization: in the main method of the main.dart file

void main() {
  //Routing configuration
  var router = new Router();
  Routers.configRouters(router);
  Application.router = router;
  runApp(MyApp());
}

1. Write routes class:

import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'rotuer_handler.dart';
import '../global/contants.dart';

class Routers{
  static String root='/';
  static void configRouters(Router router){
    //Prompt when the route cannot be found
    router.notFoundHandler = new Handler(
      handlerFunc: (BuildContext context,Map<String,List<String>> params){
        print('ERROR====>ROUTE WAS NOT FONUND!!!');
      }
    );
    //Define the route to jump to the first page
    router.define(Constant.homePage, handler: homeHandler);
  }
}

2. Write router handler file:
Handler is equivalent to a routing rule. For example, if we want to go to the detailed page, we need to pass the ID of the product, and then write a handler.

import 'package:flutter/material.dart';
import '../pages/HomePage.dart';
import 'package:fluro/fluro.dart';

Handler homeHandler = new Handler(
  handlerFunc: (BuildContext context,Map<String,List<String>> map){
    return HomePage();
  }
);

3. Static routing

import 'package:fluro/fluro.dart';

class Application{
  static Router router;
}

4. Use process

void goToHomePage(){
    ////If the page has not been skipped, skip to the page
    if(!isUserLoginPage){
      //Jump to home page and destroy current page
      Application.router.navigateTo(context, Constant.homePage);
      isUserLoginPage=true;
    }
  }

Provide status management library

Introduce:

dependencies:
    provide: ^1.0.2

Create a provision:

import 'package:flutter/material.dart';

class CurrentIndexProvide extends ChangeNotifier{
  int currentIndex = 0;
  changeIndex(int newIndex){
    currentIndex = newIndex;
    notifyListeners();
  }
}

Initialization:

void main(){
  var curProvide =CurrentIndexProvide();
  var providers  =Providers();
  providers
    ..provide(Provider<Counter>.value(curProvide));
  runApp(ProviderNode(child:MyApp(),providers:providers));
}

Get status:
You can get the status in the form of a Provide Widget.

Provide<CurrentIndexProvide>(builder: (context,child,val){
int currentIndex = Provide.value<CurrentIndexProvide>(context).currentIndex;
}

Modification status:

onTap: (index) {
            Provide.value<CurrentIndexProvide>(context).changeIndex(index);
          },

Posted on Fri, 01 Nov 2019 14:19:33 -0700 by phpbeginer