Flutterã®ç»é¢é·ç§»ã«ã¤ãã¦èããã®ã§ã¡ã¢ã ç¾ç¶ãã®ããã«ãã¦é·ç§»ãã¦ããã
Navigator.of(context).push(MaterialPageRoute( builder: (_) => HogeScreen(keyword: "..."), ));
ãã®ããæ¹ã 㨠settings.name
ãè¨å®ããã¦ããªãã®ã§ãFirebaseAnalyticsã«ãã°ãéãã¨ãã«ãªãã®ç»é¢ãªã®ãå¤å¥ã§ããªããããã°ãéãããªã
settings.name
ãè¨å®ãã
FirebaseAnalyticsObserverãå©ç¨ãã¦ç»é¢é·ç§»ã®ãã°ãéä¿¡ãããå ´åãsettings.name
ãnullã ã¨ãã°ãéãããªãã
FirebaseAnalyticsObserver class - observer library - Dart API
ãã°ãéãããã«ã¯ä»¥ä¸ã®ããã«settings.name
ãè¨å®ããããpushNamed ã使ã.
Navigator.of(context).push(MaterialPageRoute( settings: RouteSettings(name: "HogeScreen"), builder: (_) => HogeScreen(keyword: "..."), ))
pushNamed ã使ã
pushNamed ã¯ä»¥ä¸ã®ããã«ä½¿ããç»é¢é·ç§»ã®ã³ã¼ããä½åº¦ãæ¸ãå¿ è¦ããªãã¨ããã¡ãªãããããã pushNamed method - Navigator class - widgets library - Dart API
Navigator.of(context).pushNamed("HogeScreen", arguments: "...")
ããããpushNamedã«ã¯ä»¥ä¸ã®ãããªåé¡ãããã¨æã£ãã
- route name ã String ã§æ¸¡ããããå©ç¨ãã¦Route(ã¾ãã¯Widget)ãä½ãã®ã§ããã£ãããã¹ãèµ·ãããã
settings.arguments
çµç±ã§å¤ã渡ããã¨ã«ãªãã®ã§ãåãObjectã«ãªãå©ç¨ããã¨ãã«castããå¿ è¦ããããã£ãããã¹ãèµ·ãããã- route nameã ãã§ã¯ arguments ãå¿ è¦ãã©ããããããªãã®ã§ããã£ãããã¹ãèµ·ãããã
人éã®ãã£ãããã¹ãèµ·ãããããã³ã³ãã¤ã«ã¨ã©ã¼ã§ã¯ãªãå®è¡æã¨ã©ã¼ã«ãªãããææªæ°ã¥ããªããã¨ãããã
route ã¡ã½ãããã¤ãã
pushNamedã¯ç»é¢é·ç§»ã®ã³ã¼ããä½åº¦ãæ¸ãå¿ è¦ããªãã¨ããç¹ã§ã¯ä¾¿å©ã ãã©ããã£ãããã¹ãèµ·ããããã¨æããã ãããé²ãããã«ã¯ãã®ããã«Routeãçæããã¡ã½ãããæ¸ãã¦ãããã°ããã®ã§ã¯ã¨èããã
extension HogeScreenRoutes on HogeScreen { static Route<dynamic> route({@required this.keyword})) { return MaterialPageRoute( settings: RouteSettings(name: "HogeScreen"), builder: (_) => HogeScreen(keyword: "..."), ) } }
Navigator.of(context).push(HogeScreen.route());
ããããã°ãã£ããã¿ã¤ããªã©ããã¦ãå®è¡ããã¿ã¤ãã³ã°ã§ã¨ã©ã¼ã«ãªãã®ã§ã¯ãªãã³ã³ãã¤ã«ã®ã¿ã¤ãã³ã°ã§ãããã®ã§ãæé«ã ãã ããããã«ããã£ãããã¹ãèµ·ããå ´æããããHogeScreenã«æ¸¡ãå¤ãå¢ããã¨ãã ã
class HogeScreen { final String keyword; final String fuga; // å¢ãã HogeScreen({Key key, @required this.keyword, @reuqired this.fuga}); } extension HogeScreenRoutes on HogeScreen { static Route<dynamic> route({@required String keyword})) { return MaterialPageRoute( settings: RouteSettings(name: "HogeScreen"), builder: (_) => HogeScreen(keyword: keyword), // fugaã渡ããã¦ããªã ) } }
@required
ããã¦ãã¦ãã³ã³ãã¤ã«ã¨ã©ã¼ã«ãªããªããlintãåããã°ã¨ã©ã¼ã«ãããã¨ã¯ã§ããã
è¤æ°ç®æå¤æ´ããã®ãå«ãªãã³ã³ã¹ãã©ã¯ã¿ããrouteã¡ã½ãããèªåçæããã°ããããªã¨æã£ããã©ããã¾ã§ãããªãã¦ããããªã¨æã£ã¦ããã§èããã®ããããã
ãã£ã¨ããæ¹æ³ããããªãç¥ãããã
追è¨ï¼ ããããã°ä¸å¿ä¸ç®æã®å¤æ´ã§ãããã£ã¦è©±ãååã¨ãããã©ãããããæããã®ã§ããã¦ãããã
class HogeScreenArguments { final String keyword; final String fuga; HogeScreenArguments({Key key, @required this.keyword, @required this.fuga}); } class HogeScreen { final HogeScreenArguments arguments; HogeScreen({Key key, @required this.arguments}); } extension HogeScreenRoutes on HogeScreen { static Route<dynamic> route({@required HogeScreenArguments arguments})) { return MaterialPageRoute( settings: RouteSettings(name: "HogeScreen"), builder: (_) => HogeScreen(arguments: arguments), ) } }