{"id":1772,"date":"2020-04-07T09:09:00","date_gmt":"2020-04-07T01:09:00","guid":{"rendered":"http:\/\/www.imzouyang.com\/blog\/?p=1772"},"modified":"2020-11-03T13:23:36","modified_gmt":"2020-11-03T05:23:36","slug":"flutter%e8%b7%af%e7%94%b1%e6%8f%92%e4%bb%b6fluro%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"http:\/\/www.imzouyang.com\/blog\/archives\/1772.html","title":{"rendered":"Flutter\u8def\u7531\u63d2\u4ef6Fluro\u7684\u4f7f\u7528"},"content":{"rendered":"\n<p>\u672c\u6587\u662f 1.6 \u7cfb\u5217\u7248\u672c\u7684\u7528\u6cd5\uff0c1.7\u540e\u4f7f\u7528\u65b9\u5f0f\u6709\u6240\u6539\u53d8\uff0c\u5b83\u542f\u7528\u4e86\u65b0\u7684\u7c7b\u578b FluroRouter \u6765\u66ff\u4ee3\u4e4b\u524d\u7684 Router\uff0c\u76f8\u5e94\u7684\u4f7f\u7528\u7684 Router \u7c7b\u578b\u9700\u8981\u66ff\u6362\u4e3a FluroRouter\u3002<br><\/p>\n\n\n\n<p>\u6b63\u6587\u5f00\u59cb\uff1a<br><\/p>\n\n\n\n<p>Flutter\u7684\u8def\u7531\u673a\u5236\u5f88\u70e6\u7410\uff0c\u5982\u679c\u662f\u5c0f\u578b\u5e94\u7528\u8fd8\u52c9\u5f3a\u9002\u7528\uff0c\u4f46\u662f\u771f\u5b9e\u5f00\u53d1\u4e2d\u6211\u4eec\u90fd\u4f1a\u4f7f\u7528\u4f01\u4e1a\u7ea7\u7684\u8def\u7531\u673a\u5236\uff0c\u8ba9\u8def\u7531\u6e05\u6670\u53ef\u7528\u3002<\/p>\n\n\n\n<p>Fluro\u662f\u6bd4\u8f83\u597d\u7684\u4f01\u4e1a\u7ea7Flutter\u8def\u7531\u3002\u5b98\u65b9\u6709\u4f7f\u7528\u4ecb\u7ecd\uff1a <a rel=\"noreferrer noopener\" aria-label=\"https:\/\/pub.flutter-io.cn\/packages\/fluro \uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"https:\/\/pub.flutter-io.cn\/packages\/fluro\" target=\"_blank\">https:\/\/pub.flutter-io.cn\/packages\/fluro <\/a>   \u4f46\u662f\u4ecb\u7ecd\u7684\u8fd8\u4e0d\u591f\u8be6\u7ec6\u3002\u4e0b\u9762\u6839\u636e\u5b9e\u6218\u6765\u8bb0\u5f55\u4e0b Fluro \u7684\u4f7f\u7528\u59ff\u52bf\uff0c\u5206\u4e3a\u4e24\u90e8\u5206\uff0c\u7b2c\u4e00\u90e8\u5206\u662f\u89e3\u91ca\u5b98\u7f51\u7684\u4f7f\u7528\u6b65\u9aa4\u3002\u7b2c\u4e8c\u90e8\u5206\u662f\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u7684\u4e00\u822c\u4f7f\u7528\u6b65\u9aa4\u3002<\/p>\n\n\n\n<p><strong>\u7b2c\u4e00\u90e8\u5206<\/strong>\uff0c\u89e3\u91ca\u5b98\u7f51\u7684\u4f7f\u7528\u6b65\u9aa4\uff0cFluro \u6309\u7167\u5b98\u7f51\u7684\u6559\u7a0b\u6765\u770b\uff0c\u6b65\u9aa4\u5982\u4e0b<\/p>\n\n\n\n<p><strong>1\u3001<\/strong>\u5728\u5de5\u7a0b\u91cc\u5f15\u5165 Fluro\uff0c\u5728\u9879\u76ee\u7684 pubspec.yaml \u5185\u5f15\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dependencies:\n fluro: \"^1.6.3\"<\/code><\/pre>\n\n\n\n<p>\u8bb0\u5f97  pubspec.yaml \u4fee\u6539\u540e\uff0c\u9700\u8981\u6267\u884cflutter\u547d\u4ee4 flutter pub get \u4e00\u4e0b\u54e6\u3002\u628a\u5305\u90fd\u4e0b\u8f7d\u8fdb\u9879\u76ee\u91cc\u624d\u80fd\u4f7f\u7528\u3002<\/p>\n\n\n\n<p><strong>2\u3001<\/strong>\u5728\u9879\u76ee\u5185\u5b9e\u4f8b\u5316 Fluro \u7684\u4e00\u4e2a\u8def\u7531\u5b9e\u4f8b\u51fa\u6765\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import 'package:fluro\/fluro.dart';\nfinal router = Router();<\/code><\/pre>\n\n\n\n<p><strong>3\u3001<\/strong>\u4e3a\u8fd9\u4e2a\u8def\u7531\u5b9a\u4e49 \u8def\u7531\u540d\u79f0 \u548c \u5bf9\u5e94\u8def\u7531\u540d\u79f0\u7684\u5904\u7406\u903b\u8f91\uff1a<\/p>\n\n\n\n<p>\u5b9a\u4e49\u8def\u7531\uff1a\uff08\u8fd9\u91cc handler \u4f20\u5165\u7684 \u662f\u4e0b\u9762\u5b9a\u4e49\u7684\u90a3\u4e2a\u5904\u7406\u7a0b\u5e8fusersHandler\uff0c\u610f\u601d\u5c31\u662f \u8bbf\u95ee\u8def\u7531\u662f&#8221;\/users\/:id&#8221; \u5219\u6267\u884cusersHandler\u8fd9\u4e2a\u5904\u7406\u64cd\u4f5c\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>router.define(\"\/users\/:id\", handler: usersHandler);\n\u5904\u7406\u7a0b\u5e8f\uff1a\uff08\u8fd9\u4e2a\u5904\u7406\u7a0b\u5e8f\u662f \u8fd4\u56de UsersScreen \u8fd9\u4e2a\u7ec4\u4ef6\uff09<\/code><\/pre>\n\n\n\n<p>\u5904\u7406\u8def\u7531\u903b\u8f91\u7684handler\uff1a\uff08\u6b64\u5904\u793a\u4f8b handler \u662f \u8fd4\u56de UsersScreen \u8fd9\u4e2a\u6211\u4eec\u81ea\u5b9a\u4e49\u7684\u7ec4\u4ef6\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  var usersHandler = Handler(handlerFunc: (BuildContext context, Map&lt;String, dynamic> params) {\n    \/\/...\u8fd9\u91cc\u8fd8\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e9b\u64cd\u4f5c\uff0c\u53cd\u6b63\u6700\u540e return \u4e00\u4e2a\u6211\u4eec\u8def\u7531\u8df3\u8f6c\u540e\u9700\u8981\u663e\u793a\u7684\u7ec4\u4ef6\u5c31OK\n    return UsersScreen(params[\"id\"][0]);\n  });<\/code><\/pre>\n\n\n\n<p>\u81f3\u6b64\uff0c\u914d\u7f6e\u5c31\u5b8c\u6210\u4e86\uff0c\u8def\u7531\u5668\u5c06\u62e6\u622a\u8bf8\u5982\u4e4b\u7c7b\u7684  \/users\/1234 \u8def\u7531\uff0c\u5e76\u5c06\u5e94\u7528\u7a0b\u5e8f\u8def\u7531\u81f3 UsersScreen \u5c06\u503c 1234 \u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u8be5\u5c4f\u5e55\u7684\u8def\u7531\u3002\u4ee5\u6b64\u7c7b\u63a8\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u8bb8\u591a \u4e0d\u540c\u8def\u7531\u7684 \u5904\u7406\u3002<\/p>\n\n\n\n<p><strong>4\u3001<\/strong>\u90a3\u63a5\u4e0b\u6765\u600e\u4e48\u8ba9\u9879\u76ee\u4f7f\u7528\u4e0a\u8def\u7531\u5462\uff1f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u5728 MaterialApp \u7684\u914d\u7f6e\u53c2\u6570\u4e2d\uff0c\u8bbe\u7f6e onGenerateRoute: router.generator\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      title: 'Flutter Demo', \/\/\u4efb\u52a1\u7ba1\u7406\u4e0a\u663e\u793a\u7684\u540d\u5b57\n      theme: ThemeData(\n        primarySwatch: Colors.blue,\n        visualDensity: VisualDensity.adaptivePlatformDensity,\n      ),\n      onGenerateRoute: router.generator, \/\/\u8fd9\u91cc\u914d\u7f6e\u4f7f\u7528 Fluro\n      \u2026\u2026<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a onGenerateRoute \u53c2\u6570\u662f\u5728\u201c\u5f53\u8df3\u8f6c \u547d\u540d\u8def\u7531 \u65f6\u627e\u4e0d\u5230\u8be5\u8def\u7531\uff0c\u5c31\u4f1a\u8c03\u7528\u8be5\u65b9\u6cd5\u201d\uff0c\u6240\u4ee5\u8fd9\u4e2a Fluro \u5176\u5b9e\u5c31\u662f\u901a\u8fc7\u81ea\u5df1\u5c01\u88c5\u7684\u8def\u7531\u5904\u7406\u903b\u8f91\uff0c\u7136\u540e\u5728\u8fd9\u91cc\u8fdb\u884c \u5404\u4e2a\u8def\u7531\u7684\u5224\u65ad\uff0c\u7136\u540e\u6839\u636e\u5224\u65ad\u8fd4\u56de\u4e0d\u540c\u7684\u9875\u9762 \u6765\u5b9e\u73b0\u8def\u7531\u8df3\u8f6c\u7684\u3002<\/p>\n\n\n\n<p><strong>5\u3001<\/strong>\u9879\u76ee\u91cc\u8fdb\u884c\u8def\u7531\u8df3\u8f6c\uff1a<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\uff0c\u5c31\u53ef\u4ee5\u7528 Navigator.push \u6765\u8df3\u8f6c\u8def\u7531\u4e86\u3002\u4e5f\u53ef\u4ee5\u81ea\u5df1\u624b\u52a8\u63a8\u9001\u5230\u8def\u7ebf\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>router.navigateTo(context, \"\/users\/1234\", transition: TransitionType.fadeIn);<\/code><\/pre>\n\n\n\n<p>transition \u662f\u8df3\u8f6c\u52a8\u753b\uff0c\u5b83\u662f\u53ef\u9009\u547d\u540d\u53c2\u6570\uff0c\u5b83\u8fd8\u6709\u4e00\u4e9b\u503c\uff0c\u6bd4\u5982 c: TransitionType.inFromLeft \u7b49\u7b49\uff0c\u8be6\u89c1 transitionType \u7684\u5b9a\u4e49\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>enum TransitionType {\n  native,\n  nativeModal,\n  inFromLeft,\n  inFromRight,\n  inFromBottom,\n  fadeIn,\n  custom, \/\/ if using custom then you must also provide a transition\n  material,\n  materialFullScreenDialog,\n  cupertino,\n  cupertinoFullScreenDialog,\n}<\/code><\/pre>\n\n\n\n<p>\u53e6\u5916\uff0cnavigateTo \u65b9\u6cd5\u8fd8\u6709\u4e00\u4e9b\u53ef\u9009\u547d\u540d\u53c2\u6570\uff0c\u4e0b\u9762\u6e90\u7801\u76842-6\u884c\u7684\u53c2\u6570\uff0c\u6839\u636e\u9700\u8981\u9009\u62e9\u4f7f\u7528\u5373\u53ef\uff0c\u6bd4\u5982\u90a3\u4e2a transitionDuration \u5c31\u662f\u8868\u793a\u8def\u7531\u8df3\u8f6c\u52a8\u753b\u8fc7\u6e21\u7684\u65f6\u95f4\uff0cclearStack \u8868\u793a\u8df3\u8f6c\u540e\u662f\u5426\u6e05\u9664\u8def\u7531\u6808\u7b49\u7b49\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Future navigateTo(BuildContext context, String path,\n      {bool replace = false,\n      bool clearStack = false,\n      TransitionType transition,\n      Duration transitionDuration = const Duration(milliseconds: 250),\n      RouteTransitionsBuilder transitionBuilder}) {\n    RouteMatch routeMatch = matchRoute(context, path,\n        transitionType: transition,\n        transitionsBuilder: transitionBuilder,\n        transitionDuration: transitionDuration);\n    Route&lt;dynamic> route = routeMatch.route;\n    Completer completer = Completer();\n    Future future = completer.future;\n    if (routeMatch.matchType == RouteMatchType.nonVisual) {\n      completer.complete(\"Non visual route type.\");\n    } else {\n      if (route == null &amp;&amp; notFoundHandler != null) {\n        route = _notFoundRoute(context, path);\n      }\n      if (route != null) {\n        if (clearStack) {\n          future =\n              Navigator.pushAndRemoveUntil(context, route, (check) => false);\n        } else {\n          future = replace\n              ? Navigator.pushReplacement(context, route)\n              : Navigator.push(context, route);\n        }\n        completer.complete();\n      } else {\n        String error = \"No registered route was found to handle '$path'.\";\n        print(error);\n        completer.completeError(RouteNotFoundException(error, path));\n      }\n    }\n\n    return future;\n  }<\/code><\/pre>\n\n\n\n<p><br><br><br><strong>\u7b2c\u4e8c\u90e8\u5206<\/strong>\uff0c\u9879\u76ee\u4e2d\u5b9e\u9645\u5e94\u7528<\/p>\n\n\n\n<p><strong>1\u3001<\/strong>\u4e00\u822c\u6211\u4eec\u628a\u7b2c\u4e00\u90e8\u5206\u7684\u7b2c\u4e8c\u6b65\u5b9e\u4f8b\u5316\u7684 router \u653e\u5165\u4e00\u4e2a\u7c7b\u91cc\u6765\u5b9a\u4e49\uff0c\u628a Fluro \u7684 Router \u9759\u6001\u5316\uff0c\u65b9\u4fbf\u4eca\u540e\u9879\u76ee\u91cc\u5168\u5c40\u8c03\u7528\uff1a\u521b\u5efa\u4e00\u4e2a Application \u7c7b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import 'package:fluro\/fluro.dart';\nclass Application {\n  static Router router;\n}<\/code><\/pre>\n\n\n\n<p>\u5b98\u65b9\u793a\u4f8b\u4ee3\u7801\uff1a <br><a rel=\"noreferrer noopener\" aria-label=\"https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/application.dart \uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/application.dart\" target=\"_blank\">https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/application.dart <\/a><\/p>\n\n\n\n<p><strong>2\u3001<\/strong>\u65b0\u5efa\u4e00\u4e2a\u7c7b\uff0c\u5728\u91cc\u9762\u5c01\u88c5\u6240\u6709\u7684 \u5904\u7406\u8def\u7531\u7684\u903b\u8f91\u7a0b\u5e8f handler<\/p>\n\n\n\n<p>\u5b98\u65b9\u793a\u4f8b\u4ee3\u7801\uff1a <br> <a rel=\"noreferrer noopener\" aria-label=\"https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/route_handlers.dart \uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/route_handlers.dart\" target=\"_blank\">https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/route_handlers.dart <\/a><\/p>\n\n\n\n<p><strong>3\u3001<\/strong>\u65b0\u5efa\u4e00\u4e2a\u7c7b\uff0c\u5728\u91cc\u9762\u5c01\u88c5\u6240\u6709\u7684 \u5b9a\u4e49\u8def\u7531 \uff0c\u8be5\u7c7b\u540d\u5b57\u4e3a Routes \u7684\u7c7b\uff0c\u8be5\u7c7b\u91cc\u9762\u56e0\u4e3a\u4f1a\u4f7f\u7528\u4e0a\u4e00\u6b65\u7684 handler\uff0c\u6240\u4ee5\u9700\u8981\u5f15\u5165\u4e0a\u4e00\u6b65\u7684 handler \u7684\u7c7b\u5230\u6b64\u6587\u4ef6\u5185<\/p>\n\n\n\n<p>\u5b98\u65b9\u793a\u4f8b\u4ee3\u7801\uff1a<br> <a rel=\"noreferrer noopener\" aria-label=\"https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/routes.dart \uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/routes.dart\" target=\"_blank\">https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/routes.dart <\/a><br>\u8fd9\u91cc\u9762\u8fd8\u914d\u7f6e\u4e86 \u627e\u4e0d\u5230\u8def\u7531\u65f6\u7684\u5904\u7406\uff0c\u5c31\u662f\u90a3\u4e2a router.notFoundHandler<\/p>\n\n\n\n<p><strong>4\u3001<\/strong>\u9879\u76ee\u91cc\u4f7f\u7528\u65f6\uff0c\u53ea\u9700\u5f15\u5165 \u7b2c1\u6b65\u548c\u7b2c3\u6b65 \u5b9a\u4e49\u76842\u4e2a\u7c7b\u5373\u53ef\u3002\u7136\u540e\u5c31\u662f\u5b9e\u4f8b\u5316 router \u5e76\u4f7f\u7528\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    final router = Router();\n    Routes.configureRoutes(router); \/\/configureRoutes \u662f\u6211\u4eec\u81ea\u5b9a\u4e49\u7684\u4e00\u4e2astatic \u65b9\u6cd5\uff0c\u7528\u6765\u7ed3\u5408 \u5b9a\u4e49\u8def\u7531\u548c\u8def\u7531\u5904\u7406\u903b\u8f91\u7684handler\n    Application.router = router; \/\/Application \u7684 router \u662fstatic<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\u5c31\u662f\u5728  MaterialApp \u7ec4\u4ef6\u5185\u4f7f\u7528\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> MaterialApp(\n      title: 'Fluro',\n      debugShowCheckedModeBanner: false,\n      theme: ThemeData(\n        primarySwatch: Colors.blue,\n      ),\n      onGenerateRoute: Application.router.generator, \/\/\u4f7f\u7528 Fluro\n    );<\/code><\/pre>\n\n\n\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u8981\u5728\u54ea\u91cc\u7528\u8def\u7531\uff0c\u5c31\u5f15\u5165\u6700\u521d\u9759\u6001\u5316\u7684 Application \u7c7b\u5373\u53ef\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import '.\/routers\/application.dart';<\/code><\/pre>\n\n\n\n<p>\u5728\u9700\u8981\u6267\u884c\u8def\u7531\u8df3\u8f6c\u7684\u5730\u65b9\u64b8\u4e0a\u5373\u53ef\u5b9e\u73b0\u8def\u7531\u8df3\u8f6c\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Application.router.navigateTo(context,\"\/users\/1234\"); <\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><br><strong>PS\uff1a<\/strong><\/p>\n\n\n\n<p><strong>1\u3001<\/strong>\u5982\u4f55\u56de\u4f20\u503c\uff1a\u300afutter \u6280\u672f\u5165\u95e8\u4e0e\u5b9e\u6218\u300b\u7b2c\u4e8c\u724811.2\u8282 \u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    Routes.router.navigateTo(\n        context, '${Routes.page2}?message=$json',\/\/\u8df3\u8f6c\u8def\u5f84\n        transition: TransitionType.inFromRight\/\/\u8fc7\u573a\u6548\u679c\n    ).then(   (result) {     \/\/\u56de\u4f20\u503c\n      if (result != null) {\n        message = result;\n      }\n    }\n   );<\/code><\/pre>\n\n\n\n<p>\u5728\u9875\u9762\u5185\u8fdb\u884c\u8df3\u8f6c\u65f6\uff0c\u53ef\u4ee5 .then\uff0c\u5b9a\u4e49\u597d \u7528\u4e8e\u7b2c\u4e8c\u4e2a\u9875\u9762\u8df3\u8f6c\u56de\u6765\u65f6\u63a5\u6536\u6570\u636e\u7684\u5904\u7406\u903b\u8f91\u3002\u4e3a\u4ec0\u4e48\u53ef\u4ee5.then \uff0c\u662f\u56e0\u4e3a \u672c\u6587\u7b2c\u4e00\u90e8\u5206\u7b2c5\u70b9\u8d34\u7684 navigateTo \u7684\u6e90\u7801\u53ef\u4ee5\u770b\u5230\uff0cnavigateTo \u8fd4\u56de\u7684\u662f Future\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e8c\u4e2a\u9875\u9762\u4f7f\u7528 Navigator.pop() \u65b9\u6cd5\u6765\u56de\u4f20\u6570\u636e\uff0c<\/p>\n\n\n\n<p><a href=\"https:\/\/api.flutter-io.cn\/flutter\/widgets\/Navigator\/pop.html\">Navigator.pop()<\/a>&nbsp;\u65b9\u6cd5\uff0c\u4f1a\u4ece\u5bfc\u822a\u5668\u5806\u6808\u4e0a\u79fb\u9664&nbsp;Route&nbsp;\u5bf9\u8c61\u3002\u4e5f\u5c31\u662f\u8fd4\u56de\u4e0a\u4e00\u4e2a\u8def\u7531\uff0c\u4f7f\u7528 Navigator.pop(context);  \u5b83\u8fd8\u6709\u7b2c\u4e8c\u4e2a\u53ef\u9009\u53c2\u6570\uff0c\u8be5\u53c2\u6570\u4e3a\u9875\u9762\u5173\u95ed\u65f6\u8fd4\u56de\u7ed9\u4e0a\u4e00\u4e2a\u9875\u9762\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Navigator.pop(context, '\u6765\u81ea\u7b2c\u4e8c\u4e2a\u754c\u9762\u7684\u6570\u636e')<\/code><\/pre>\n\n\n\n<p><strong>2\u3001<\/strong>\u8def\u7531\u8df3\u8f6c\u65f6\u7684\u53c2\u6570\u4f20\u9012\u4e0e\u53c2\u6570\u903b\u8f91\u5904\u7406<\/p>\n\n\n\n<p>1\uff09\u53c2\u6570\u5982\u4f55\u4f20\u9012\u5230\u65b0\u8def\u7531\u9875\u9762\u90a3\u8fb9\u5462\uff1f<\/p>\n\n\n\n<p>\u8def\u7531\u8df3\u8f6c\u65f6\u901a\u8fc7 \u8def\u7531url \u6765\u4f20<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>router.define(\"\/users\/:id\", handler: usersHandler);<\/code><\/pre>\n\n\n\n<p>\u66f4\u591a\u7684\u8def\u7531\u4f20\u53c2\u7684url\u5b9a\u4e49\uff0c\u53ef\u4ee5\u770b\u5b98\u65b9\u793a\u4f8b\u4ee3\u7801\uff1a<a href=\"https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/routes.dart\">https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/routes.dart<\/a><br>handler \u91cc\u9762\u901a\u8fc7 params \u6765\u83b7\u53d6\u5e76\u5904\u7406\uff0c\u8bf7\u770b\u4e0b\u9762 handler \u5904\u7406\u53c2\u6570<\/p>\n\n\n\n<p>2\uff09\u5982\u4f55\u5904\u7406\u63a5\u6536\u5230\u7684\u4e0a\u4e00\u4e2a\u8def\u7531\u9875\u9762\u4f20\u9012\u8fc7\u6765\u7684\u6570\u636e\u5462\uff1f<br>\u901a\u8fc7\u5b98\u65b9 handler \u793a\u4f8b\u5c31\u53ef\u4ee5\u770b\u51fa \u53c2\u6570\u7684\u5904\u7406\u90fd\u662f\u5728\u8fd9\u91cc\u8fdb\u884c\uff0cHandler \u7684 handlerFunc \u53c2\u6570\u5185\u53ef\u4ee5\u5904\u7406\u4f20\u9012\u7684\u53c2\u6570\uff1a<a href=\"https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/route_handlers.dart\">https:\/\/github.com\/theyakka\/fluro\/blob\/master\/example\/lib\/config\/route_handlers.dart<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var demoRouteHandler = Handler(\n    handlerFunc: (BuildContext context, Map&lt;String, List&lt;String>> params) {\n  String message = params[\"message\"]?.first;  \/\/\u5904\u7406\u53c2\u6570\n  String colorHex = params[\"color_hex\"]?.first;\n  String result = params[\"result\"]?.first;\n  Color color = Color(0xFFFFFFFF);\n  if (colorHex != null &amp;&amp; colorHex.length > 0) {\n    color = Color(ColorHelpers.fromHexString(colorHex));\n  }\n  return DemoSimpleComponent(message: message, color: color, result: result);  \/\/\u4f7f\u7528\u53c2\u6570\n});<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u662f 1.6 \u7cfb\u5217\u7248\u672c\u7684\u7528\u6cd5\uff0c1.7\u540e\u4f7f\u7528\u65b9\u5f0f\u6709\u6240\u6539\u53d8\uff0c\u5b83\u542f\u7528\u4e86\u65b0\u7684\u7c7b\u578b FluroRouter \u6765\u66ff\u4ee3\u4e4b\u524d &hellip; <a href=\"http:\/\/www.imzouyang.com\/blog\/archives\/1772.html\" class=\"read-more\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text sr-only\">Flutter\u8def\u7531\u63d2\u4ef6Fluro\u7684\u4f7f\u7528<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"aside","meta":[],"categories":[30],"tags":[],"_links":{"self":[{"href":"http:\/\/www.imzouyang.com\/blog\/wp-json\/wp\/v2\/posts\/1772"}],"collection":[{"href":"http:\/\/www.imzouyang.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.imzouyang.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.imzouyang.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.imzouyang.com\/blog\/wp-json\/wp\/v2\/comments?post=1772"}],"version-history":[{"count":12,"href":"http:\/\/www.imzouyang.com\/blog\/wp-json\/wp\/v2\/posts\/1772\/revisions"}],"predecessor-version":[{"id":2361,"href":"http:\/\/www.imzouyang.com\/blog\/wp-json\/wp\/v2\/posts\/1772\/revisions\/2361"}],"wp:attachment":[{"href":"http:\/\/www.imzouyang.com\/blog\/wp-json\/wp\/v2\/media?parent=1772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.imzouyang.com\/blog\/wp-json\/wp\/v2\/categories?post=1772"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.imzouyang.com\/blog\/wp-json\/wp\/v2\/tags?post=1772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}