Try using 'as prefix' for one of the import directives..

错误产生背景

Flutter更新了1.22后,pubspec.yaml中引用fluro: ^1.6.3

错误内容

The name 'Router' is defined in the libraries 'package:fluro/src/router.dart (via package:fluro/fluro.dart)' and 'package:flutter/src/widgets/router.dart'.

Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.

解决办法

原:
import 'package:fluro/fluro.dart'
新:
import 'package:fluro/fluro.dart' as CustomRouter;

原:

///使用fluro进行路由管理
class XRouter {
  static CustomRouter router;
 static void init() {
    router = Router();
 configureRoutes(router);
 }
  ///路由配置
 static void configureRoutes(Router router) {
    router.notFoundHandler = Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      print("route is not find !");
 return null; });
 //网页加载
 router.define('/web', handler: Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      String title = params['title']?.first;
 String url = params['url']?.first;
 return WebViewPage(url, title);
 }));
 }

新:

///使用fluro进行路由管理
class XRouter {
  static CustomRouter.Router router;
 static void init() {
    router = CustomRouter.Router();
 configureRoutes(router);
 }
  ///路由配置
 static void configureRoutes(CustomRouter.Router router) {
    router.notFoundHandler = CustomRouter.Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      print("route is not find !");
 return null; });
 //网页加载
 router.define('/web', handler: CustomRouter.Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      String title = params['title']?.first;
 String url = params['url']?.first;
 return WebViewPage(url, title);
 }));
 }

评论

暂无评论