selectMenuPath method

void selectMenuPath(
  1. String path
)

Implementation

void selectMenuPath(String path) {
  if(state is! MenuLoadSuccess) return;
  MenuLoadSuccess old = state as MenuLoadSuccess;
  MenuNode root = MenuNode(
    path: '',
    label: '',
    deep: -1,
    children: old.state.items,
  );
  List<MenuNode> result = findNodes(root, Uri.parse(path), 0, '/', []);
  if (result.isNotEmpty) {
    List<String> expandMenus = [];
    if (result.length > 1) {
      expandMenus.addAll(
          result.sublist(0, result.length - 1).map((e) => e.path).toList());
    }
    emit(MenuLoadSuccess(
      silentActive: true,
      state: old.state.copyWith(
        expandMenus: expandMenus,
        activeMenu:  result.last.path
      ),
    ));
  }
}