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

Viewed 25

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?

1 Answers

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,
),
Related