Search code examples
flutterdartflutter-text

How to change default fontFamily of app depending on OS(iOS or Android) in flutter?


I want to create an app that feels native on both iOS and Android. On iOS, I want to use SF Pro text, and on Android different fontFamily. Does anyone have tried to do it before?


Solution

  • You can check current platform and assign font family based on it.

    String? get appFontFamily {
      if (kIsWeb) {
        return null;
      }
      if (Platform.isAndroid) {
        return ""; //provide proper name
      }
      if (Platform.isIOS) {
        return ""; //provide proper name
      }
    }
    

    And place this getter on MaterialApp

    theme: ThemeData(
      fontFamily: appFontFamily,
      primarySwatch: Colors.blue,
    ),