问题描述
我正在使用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.
Material
和MaterialApp
有什么区别?
推荐答案
MaterialApp
是一个小部件,其中引入了许多有趣的工具,例如Navigator
或Theme
来帮助您开发应用程序.
MaterialApp
is a widget that introduces many interesting tools such as Navigator
or Theme
to help you develop your app.
Material
是一个小部件,用于定义遵循Material规则的UI元素.它定义了什么是海拔,形状和东西.然后被许多重要的小部件(例如Appbar
或Card
或FloatingButton
)重用.
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
.然后,当您要使用Text
或InkWell
时,请使用引入Material
实例(例如Scaffold
,Appbar
,Dialog
等)的小部件.
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有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!