【问题标题】:Things to be aware of when using a container as a parent instead of MaterialApp/Scaffold使用容器作为父容器而不是 MaterialApp/Scaffold 时需要注意的事项
【发布时间】:2020-06-03 02:37:13
【问题描述】:

假设我正在构建一个不需要 Material 设计元素并使用容器作为父级的应用。

在使用 MaterialApp/Scaffold 时是否需要手动设置(布局方面)而不必要?

以下是我在使用容器作为父容器时注意到的一些意外行为: • 文本小部件中的黄线(使用 Scaffold 时这些线会消失) • 即使我设置了约束条件,ClipRRect 小部件也会占据整个屏幕

【问题讨论】:

    标签: flutter containers flutter-layout scaffold


    【解决方案1】:

    Material 类是 UI 的主要组件。使用 Material Widget 作为父级并不意味着您必须为整个应用使用 Material Design,您可以自己定制 Widget、UI 等。 p>

    作为官方文档的一部分:

    The Material widget is responsible for:
    
    Clipping: If clipBehavior is not Clip.none, Material clips its widget sub-tree to the shape specified by shape, type, and borderRadius. By default, clipBehavior is Clip.none for performance considerations.
    Elevation: Material elevates its widget sub-tree on the Z axis by elevation pixels, and draws the appropriate shadow.
    Ink effects: Material shows ink effects implemented by InkFeatures like InkSplash and InkHighlight below its children.
    

    它还负责为您的文本提供默认样式(这就是您看到黄色下划线的原因)。

    不过,请记住,您正在为移动客户端制作应用程序,因此,您应该使用 MaterialAppCupertinoApp 开箱即用的一些最佳实践,即使您决定在应用程序中采用自己的路径,使用您自己的自定义 Widgets

    【讨论】:

    • 感谢您的澄清!
    • 不客气!如果我的回答对你有帮助,记得将其标记为正确,以帮助有同样疑问的其他人。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-26
    • 2017-03-01
    相关资源
    最近更新 更多