navigatorPush static method

dynamic navigatorPush(
  1. BuildContext context,
  2. Widget widget,
  3. String name, {
  4. bool add = false,
  5. bool replace = false,
  6. bool fullscreenDialog = false,
  7. bool match = false,
  8. Offset? center,
  9. dynamic back,
})

公共打开方式

Implementation

static navigatorPush(BuildContext context, Widget widget, String name,
    {bool add = false,
    bool replace = false,
    bool fullscreenDialog = false,
    bool match = false,
    Offset? center,
    back}) {
  try {
    FocusScope.of(context).unfocus();
    var route = match
        ? CirclePageRoute(
            fullscreenDialog: fullscreenDialog,
            settings: RouteSettings(name: name),
            center: center,
            builder: (context) => widget)
        : CupertinoPageRoute(
            fullscreenDialog: fullscreenDialog,
            settings: RouteSettings(name: name),
            builder: (context) => widget);
    if (add) {
      if (routeMap[name]?.isActive == true) {
        Navigator.removeRoute(context, routeMap[name]);
      }
      routeMap[name] = route;
    }
    if (replace) {
      Navigator.pushReplacement(context, route).then((value) {
        back?.call(value);
        return value;
      });
    } else {
      Navigator.push(context, route).then((value) {
        back?.call(value);
        return value;
      });
    }
  } catch (e) {
    AppConfig.printLog(e);
  }
}