Member-only story

Flutter Platform Adaptations Helper Classes

Fred Grott
3 min readSep 25, 2023

The flutter platform adaptations doc has some glaring errors. This is an article series to fix those errors.

First Fix, The Correct Way To Access Platform Detection To Not Mess Up Simulating Platforms During Testing

To ensure we can simulate platform testing via debugDefaultTargetPlatformOverride one needs to detect the platform via Theme.of(context) constructs. Thus, it is helpful to create a class that does exactly that:

Then in any flutter doc where it says Platform.isIOS replace that with RunningPlatform.isIOS(context). And now we have a very useful helper to build the other helper methods and classes.

Adaptive Text Fields

Now using the RunningPlatform class we can create an adaptive text fields helper:

--

--

Fred Grott
Fred Grott

Responses (1)