Flutter中的Material和MaterialApp有什么区别? [英] What is the difference between Material and MaterialApp in Flutter?

查看:1630
本文介绍了Flutter中的Material和MaterialApp有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flutter开发一个应用程序.如果我选择MaterialApp作为应用程序的父窗口小部件,则应用程序中的所有Text小部件都带有黄色下划线.另一方面,如果我仅使用Material作为父窗口小部件,则Text小部件下不会显示黄线.

I am developing an app using Flutter. If I choose MaterialApp as the parent widget of my app, all Text widgets in my app are underlined yellow. On the other hand, if I just use Material as the parent widget, no yellow lines are shown under the Text widgets.

MaterialMaterialApp有什么区别?

推荐答案

MaterialApp是一个小部件,其中引入了许多有趣的工具,例如NavigatorTheme来帮助您开发应用程序.

MaterialApp is a widget that introduces many interesting tools such as Navigator or Theme to help you develop your app.

Material是一个小部件,用于定义遵循Material规则的UI元素.它定义了什么是海拔,形状和东西.然后被许多重要的小部件(例如AppbarCardFloatingButton)重用.

Material is, on the other hand, a widget used to define a UI element respecting Material rules. It defines what elevation is, shape, and stuff. Then reused by many material widgets such as Appbar or Card or FloatingButton.

Text中可以找到的黄色下划线由MaterialApp引入,作为后备Theme.此处是出于调试目的,警告您需要在Text上方的某个地方使用Material.

The yellow underlines you can find in Text is introduced by MaterialApp as a fallback Theme. It is here for debug purpose, to warn you that you need to use Material somewhere above your Text.

简而言之,请同时使用两者.您的应用程序根目录附近应该有一个MaterialApp.然后,当您要使用TextInkWell时,请使用引入Material实例(例如ScaffoldAppbarDialog等)的小部件.

In short, use both. You should have a MaterialApp near the root of your app. And then use widgets that introduce a Material instance (Such a Scaffold, Appbar, Dialog, ...) when you want to use Text or InkWell.

这篇关于Flutter中的Material和MaterialApp有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆