Skip to content Skip to sidebar Skip to footer

Force Flutter Android Application To Behave Like It Is On An Ios Device

Is there a way to force an Flutter Android App to behave like it is on an iOS Device? I'm not referring to the Cupertino package. Here is what I mean with Android/iOS Style iOS Sty

Solution 1:

You can set the platform parameter in the ThemeData of the app to TargetPlatform.iOS. Then the app will behave as if it were running on an iOS device, including showing iOS text controls, etc. Very useful for testing things out at least!

Here's a full app that will use iOS stylings even when run on an Android device:

import'package:flutter/material.dart';
import'package:flutter/widgets.dart';

voidmain() {
  runApp(
    MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        // The line below forces the theme to iOS.platform: TargetPlatform.iOS,
      ),
      home: Scaffold(
        body: Center(
          child: TextField(),
        ),
      ),
    ),
  );
}

Solution 2:

Update

This is not valid anymore with latest Flutter version

Solution from Previous Versions

Yes, it is possible during development stage, if that is what you want.

If the App is started from Intellij/Android studio, open Flutter Performance tab from Intellij/Android Studio, there you can find the option Platform and you can toggle it between iOS and Android.

If you are launching app from command line and using flutter devtools, in Devtools Web Interface, go to tab Flutter Inspector, there you can find the option Platform and you can toggle it between iOS and Android.

Solution 3:

Use debugDefaultTargetPlatformOverride to force it, obviously in debug:


Widget build(BuildContext context) {
    debugDefaultTargetPlatformOverride = TargetPlatform.iOS;

    return PlatformApp(
      title: 'Lovey-Dovey',
      home: MyHomePage(title: 'Lovey-Dovey2'),
    );
  }

Solution 4:

Flutter will default the style to the native platform. So iOS/Android apps, while maintaining similar functionality, won't look out of place on the phone as they will follow Cupertino/Material guidelines respectively.

Post a Comment for "Force Flutter Android Application To Behave Like It Is On An Ios Device"