bdlukaa / fluent_ui

Implements Microsoft's WinUI3 in Flutter.
https://bdlukaa.github.io/fluent_ui/
BSD 3-Clause "New" or "Revised" License
2.97k stars 464 forks source link

When using the NavigationView control, if the text in the secondary menu is too long, it will overflow due to elastic expansion and contractionπŸ› #1098

Closed MyCocos closed 3 months ago

MyCocos commented 3 months ago

class HomeScreenView extends GetView { HomeScreenView({super.key});

final viewKey = GlobalKey(debugLabel: 'Navigation View Key');

@override Widget build(BuildContext context) { var themeIconName = controller.mode.value == ThemeMode.light ? "lightTheme".tr : "darkTheme".tr; controller.themeIconData.value = controller.mode.value == ThemeMode.light ? FluentIcons.lower_brightness : FluentIcons.light; return Obx( () => FluentApp( scrollBehavior: MyCustomScrollBehavior(), // <== add here builder: FlutterSmartDialog.init(), themeMode: controller.mode.value, debugShowCheckedModeBanner: true, //color: controller.color, theme: FluentThemeData.light(), darkTheme: FluentThemeData.dark(), locale: controller.locale, home: NavigationView( key: viewKey, appBar: NavigationAppBar( title: Text("admin_name".tr), leading: IconButton( icon: const Icon(FluentIcons.home, size: kDefaultPadding), onPressed: () { debugPrint('head to'); }, ), actions: Row( children: [ const Spacer(flex: 40), //δΈ»ι’˜εˆ‡ζ’ Expanded( flex: 4, child: Padding( padding: const EdgeInsets.only(top: kDefaultPadding * 0.4), child: Visibility( visible: (MediaQuery.of(context).size.width > kScreenWidthXl), child: IconButton( icon: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(semanticLabel: themeIconName, controller.themeIconData.value, size: kDefaultPadding), Text(themeIconName), ], ), onPressed: () { //setState(() { controller.mode.value = ShowUtils().updateTheme();

                      //themeIconName;
                      // controller.themeIconData.value = controller.mode == ThemeMode.light ? FluentIcons.lower_brightness : FluentIcons.light;
                      //});
                    },
                  ),
                ),
              ),
            ),

            //θ―­θ¨€εˆ‡ζ’
            Expanded(
              flex: 5,
              child: Padding(
                padding: const EdgeInsets.only(top: kDefaultPadding * 0.4, left: kDefaultPadding * 0.3, right: kDefaultPadding * 1.0),
                child: Visibility(
                  visible: (MediaQuery.of(context).size.width > kScreenWidthXl),
                  child: DropDownButton(
                    title: Row(
                      children: [
                        const Icon(FluentIcons.locale_language, size: kDefaultPadding),
                        Padding(
                          padding: const EdgeInsets.only(left: kDefaultPadding * 0.5),
                          child: Text("language".tr),
                        ),
                      ],
                    ),
                    items: [
                      MenuFlyoutItem(
                        onPressed: () async {
                          // ref.read(localChange.notifier).update((state) => state = ShowUtils.updateLocation(LanguageType.values[0]));
                          ShowUtils.updateLocation(0, LanguageType[0]);
                        },
                        text: Text(LanguageType[0]),
                      ),
                      MenuFlyoutItem(
                        onPressed: () async {
                          //ref.read(localChange.notifier).update((state) => state = ShowUtils.updateLocation(LanguageType.values[1]));
                          ShowUtils.updateLocation(1, LanguageType[1]);
                        },
                        text: Text(LanguageType[1]),
                      ),
                    ],
                  ),
                ),
              ),
            ),
            // //η”¨ζˆ·δΏ‘ζ―
            Expanded(
              flex: 2,
              child: Padding(
                padding: const EdgeInsets.only(top: kDefaultPadding * 0.4, left: kDefaultPadding * 0.3, right: kDefaultPadding * 1.0),
                child: IconButton(
                  //tooltip: context.L!.admin,
                  //padding: const EdgeInsets.only(top: kDefaultPadding * 0.6, left: kDefaultPadding * 0.2),
                  onPressed: () {
                    AwesomeDialog? dialog; // εœ¨θΏ™ι‡Œε£°ζ˜Ž dialog ε˜ι‡
                    dialog = AwesomeDialog(
                      context: context,
                      dialogType: DialogType.noHeader,
                      width: kDialogWidth,
                      body: AdminInfoView(
                        context: context,
                        onAccountButtonPressed: () {
                          //const MyProfileRoute().go(context);
                        },
                        onLogoutButtonPressed: () {
                          dialog?.dismiss();
                          Utils.logout();
                          //userAppRouter().go(RoutePath.LOGIN);
                          Get.off(LoginScreenView());
                        },
                      ),
                      //padding: const EdgeInsets.only(bottom: 0, left: 0),
                      alignment: Alignment.topRight,
                      onDismissCallback: (type) {},
                    );
                    dialog.show();
                  },
                  icon: const Icon(FluentIcons.account_management, size: kDefaultPadding),
                ),
              ),
            ),
          ],
        ),
      ),
      onDisplayModeChanged: (mode) {
        debugPrint('η‚Ήε‡»θœε•εˆ‡ζ’ζ˜Ύη€Ίεˆ‡ζ’ to $mode');
      },
      pane: NavigationPane(
        selected: controller.topIndex.value,
        //indicator: indicators[indicator],
        onItemPressed: (index) {
          //Do anything you want to do, such as:
          //if (index == topIndex) {
          //if (displayMode == PaneDisplayMode.open) {
          //  setState(() => this.displayMode = PaneDisplayMode.compact);
          //} else if (displayMode == PaneDisplayMode.compact) {
          //  setState(() => this.displayMode = PaneDisplayMode.open);
          //}
          //}
          debugPrint('η‚Ήε‡»θœε•Changed to $index');
        },
        onChanged: (index) => controller.topIndex = index.obs,
        //setState(() => topIndex = index),
        displayMode: controller.displayMode,
        toggleable: true,
        // header: Text("menuDisplay".tr),
        size: const NavigationPaneSize(openMaxWidth: kDefaultPadding * 15.0),
        leading: IconButton(
          icon: const Icon(FluentIcons.home),
          onPressed: () {
            debugPrint('head to');
          },
        ),
        items: controller.getMenu(),
      ),
    ),
  ),
);

} }

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 List getMenu() { var menuList = StoreUtil.getMenuList(); List menus = []; // εˆ›ε»ΊδΈ€δΈͺη©Ίηš„ List 对豑 for (var v in menuList) { if (v.parentId > 0) { continue; } // ζ·»εŠ ε­θœε•ι‘Ή bool isChildMenu = false; for (var v1 in menuList) { if (v1.parentId == v.id) { isChildMenu = true; break; } } if (isChildMenu == true) { var children = PaneItemExpander( icon: Icon(_menusIconData(v.icon), size: kDefaultPadding), items: _getMenuChild(v.id, menuList), title: Text(v.menuName), onTap: () { onMenuActionClick(v.path, v.menuName); }, body: tabView.value, ); menus.add(children); } else { var children = PaneItem( icon: Icon(_menusIconData(v.icon), size: kDefaultPadding), title: Text(v.menuName), onTap: () { onMenuActionClick(v.path, v.menuName); }, body: tabView.value, ); menus.add(children); } } return menus; }

List _getMenuChild(int menuId, var list) { List subMenuItems = []; // ζ·»εŠ ε­θœε•ι‘Ή for (var v in list) { if (v.parentId == menuId) { // ζ·»εŠ ε­θœε•ι‘Ή bool isChildMenu = false; for (var v1 in list) { if (v1.parentId == v.id) { isChildMenu = true; break; } } if (isChildMenu == true) { var children = PaneItemExpander( icon: Icon(_menusIconData(v.icon), size: kDefaultPadding), items: _getMenuChild(v.id, list), title: Text(v.menuName), onTap: () { onMenuActionClick(v.path, v.menuName); }, body: tabView.value, ); subMenuItems.add(children); } else { var children = PaneItem( icon: Icon(_menusIconData(v.icon), size: kDefaultPadding), title: Text(v.menuName), onTap: () { onMenuActionClick(v.path, v.menuName); }, body: tabView.value, ); subMenuItems.add(children); } } } return subMenuItems; }

bdlukaa commented 3 months ago

Please, use the issue template. It is impossible to read the issue like this.