简体   繁体   English

我想将下面的代码转换成 Cupertino, IOS 风格。 但是我不能使用 IOS 样式的抽屉菜单。 为什么? 我该如何使用?

[英]I want to convert the code below into Cupertino, IOS style. But I Can't Use Drawer Menu for IOS style. Why? How can I use?

I want to make android and IOS style.我想制作 android 和 IOS 样式。

I want to convert the code below into Cupertino, IOS style.我想将下面的代码转换成 Cupertino, IOS 风格。

But I Can't Use Drawer Menu for IOS style.但是我不能使用 IOS 样式的抽屉菜单。 Why?为什么? How can I use?我该如何使用?

return Scaffold(
    key: _scaffoldKey,
    drawer: Drawer(),
    appBar: AppBar(
      leading: IconButton(
        onPressed: () {
          Navigator.pop(context);
        },
        icon: Icon(
          Icons.arrow_back_ios,
          color: MyColors.blue,
        ),
      ),
      centerTitle: true,
      title: Text('Test', style: MyTextStyles.appBarTitle(deviceType) ),
      actions: <Widget>[
        Builder(
          builder: (BuildContext context) => PlatformIconButton(
            onPressed: () {
              Scaffold.of(context).openDrawer();
            },
            icon: Icon(
              Icons.menu,
            )))])
    body: .........

The Drawer widget is a Material-exclusive widget, and you can't use it directly on iOS. Drawer widget 是 Material 独有的 widget,不能直接在 iOS 上使用。

You could build your own "Drawer-like" widget for iOS by replicating the build construction of a Drawer widget, but I would not recommend that, because drawers don't have that iOS "look and feel".您可以通过复制抽屉小部件的构建构造来为 iOS 构建自己的“类似Drawer ”的小部件,但我不建议这样做,因为抽屉没有 iOS 的“外观和感觉”。 As an iOS user myself, I know some very influential apps like Twitter have something that looks like a Drawer, but I think that is not the way a native iOS app would handle that kind of navigation.作为 iOS 用户,我知道一些非常有影响力的应用程序,如 Twitter 有一些看起来像抽屉的东西,但我认为这不是原生 iOS 应用程序处理这种导航的方式。

What you can do instead, is having a Drawer widget for Android, and a bottom tab bar for iOS, which is a component that is way more common in iOS-styled apps.相反,您可以做的是为 Android 使用Drawer小部件,为 iOS 使用底部标签栏,这是一个在 iOS 风格的应用程序中更常见的组件。 You can use the Platform class to check if your code is being executed on Android or iOS, and choose the right widget based on that.您可以使用Platform class 检查您的代码是否正在 Android 或 iOS 上执行,并根据此选择正确的小部件。

Here is one example of such a build logic that you might find useful.这是您可能会发现有用的此类构建逻辑的一个示例。 I am very sorry I can't paste the code directly, I had this screenshot from a presentation I made and I don't remember where did I place the code for this project, but I hope you find it useful.非常抱歉,我不能直接粘贴代码,我从我的演示文稿中得到了这张截图,我不记得我把这个项目的代码放在哪里了,但我希望你觉得它有用。 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM