最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Is there a simple way in Flutter to get the style details that a Widget WOULD have if built - Stack Overflow

programmeradmin0浏览0评论

I find I often have the same problem. I am making a widget, and I want it to look "normal", which requires some manual tweak for some reason. In that case, I want to find out, "If I made a TextButton, what color would the text be?" I find that this question is insanely difficult to answer. Sometimes, keeping this hypothetical, I want to make a Text widget and I want to manually make the color "whatever color a TextButton would have right here." Again, infuriatingly difficult to answer. Am I missing something?

First, you have to REALLY dig through the docs to find the magic name of some property to know what you're looking for. In my example, for instance, I have learned that it is the TextButton's style.foregroundColor that controls the text color. BUT, how to find out what a TextButton's text color WOULD BE if I made one? Well, maybe I could use Theme.of(context).textButtonTheme. Well, yes, if there is one set, that works. BUT, it's entirely possible that this is null. And, if you use Theme.of(context).textButtonTheme.style.foregroundColor and it is null, it's not like it defaults to whatever other value an actual TextButton would then default to. Nope, it just returns null. In that case, I have no idea what theme/style value TextButton goes to next to set its own text color.

Here's the point, is there ANY WAY to look for style info "backwards", meaning look it up by Widget class or something? Or, is this all a lot simpler than I am making it out to be?

Even if there was some obscure chart that lists the Theme property that actually defines each thing (e.g., TextButton's text color), that would be fine. Instead, I can't even tell which object to look for. It is the Theme's TextButtonTheme IF THAT EXISTS. If not, it's...something else.

Any ideas?

发布评论

评论列表(0)

  1. 暂无评论