Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 3
    Only this answer is up-to-date with the latest Flutter framework. The rest answers are not wrong but defaultTargetPlatform seems to be no longer part of the framework Commented Dec 10, 2017 at 14:31
  • 1
    This solution allow you to change the platform during tests, something that I couldn't with Platform.isIOS Commented Feb 3, 2021 at 6:24
  • 5
    Watch out on this solution. If it's called in initstate() it will throw an exception as Theme.of() is a inherited widgets and will listen to changes. Which cannot be done in initstate() so it throws exception Commented Jun 13, 2022 at 20:51
  • The problem of this answer is Theme.of(context) can cause unnecessary rebuilds, you can check this issue on github: github.com/flutter/flutter/issues/89127 Commented Jul 7, 2024 at 11:51