Flutter different theme for Android and iOs

0 votes

I want to use a different theme for my flutter app, depending on the OS it's started on. How can I detect the OS when choosing what theme to apply?

Theme.of(context).platform == TargetPlatform.iOS

doesn't work, because I haven't applied a theme yet...

Nov 23, 2022 in Android by Ashwini
• 5,430 points
1,130 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You can easily override theme by wrapping your view into a new Theme instance with custom properties.

You could do the following :

return new MaterialApp(
  // default theme here
  theme: new ThemeData(),
  builder: (context, child) {
    final defaultTheme = Theme.of(context);
    if (defaultTheme.platform == TargetPlatform.iOS) {
      return new Theme(
        data: defaultTheme.copyWith(
          primaryColor: Colors.purple
        ),
        child: child,
      );
    }
    return child;
  }
);

Which would specify a default theme. And then override primaryColor for IOS.

answered Nov 28, 2022 by sarit
• 1,830 points

edited Mar 5, 2025

Related Questions In Android

+1 vote
0 answers

Android Open External Storage directory(sdcard) for storing file

For programmatic file saving, I want to ...READ MORE

Sep 21, 2022 in Android by Edureka
• 13,750 points
1,623 views
0 votes
1 answer
0 votes
1 answer

Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

Go to the gradle.properties file and add ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 12,730 points
1,664 views
0 votes
1 answer

Android Shared preferences for creating one time activity

Android offers a variety of options for ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 12,730 points
1,014 views
+1 vote
1 answer
0 votes
1 answer

Dart_LoadScriptFromKernel: The binary program does not contain 'main'.

save the code and it will be ...READ MORE

answered Jun 8, 2022 in Others by anonymous

edited Mar 5, 2025 4,758 views
0 votes
1 answer

How to install Dart in Windows system?

Hi@akhtar, Dart is the programming language used to code Flutter apps. ...READ MORE

answered Jul 21, 2020 in Others by MD
• 95,460 points
2,014 views
0 votes
1 answer

flutter run: No connected devices

Hi@akhtar, To prepare to run and test your ...READ MORE

answered Jul 21, 2020 in Others by MD
• 95,460 points
5,189 views
0 votes
1 answer

How to create a function in Dart language?

Hi@akhtar, There are many function types available in ...READ MORE

answered Jul 22, 2020 in Others by MD
• 95,460 points
1,449 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP