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 22, 2022 in Mobile Development by gaurav
• 23,260 points
732 views

1 answer to this question.

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 25, 2022 by gaurav
• 23,260 points

Related Questions In Mobile Development

0 votes
0 answers

is there any working twitter integration for android and ios

I have tried so many codes for ...READ MORE

Nov 11, 2022 in Mobile Development by gaurav
• 23,260 points
352 views
0 votes
0 answers
0 votes
0 answers

What is the new URL schema for Here WeGo v4 on iOS/Android?

The URL schema for Here WeGo on ...READ MORE

Nov 10, 2022 in Mobile Development by gaurav
• 23,260 points
535 views
0 votes
0 answers
0 votes
1 answer

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

Hi@akhtar, You need to add the main() function ...READ MORE

answered Jul 21, 2020 in Others by MD
• 95,460 points
3,579 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
1,136 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
4,136 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
760 views
0 votes
1 answer

Flutter project in iOS emulator takes forever to run, but its worked on Android emulator

Try flutter clean and flutter build ios ...READ MORE

answered Nov 18, 2022 in Mobile Development by gaurav
• 23,260 points
653 views
0 votes
1 answer

iOS 13 Custom Fonts download and installation

Step 1: From the Home screen, tap ...READ MORE

answered Dec 15, 2022 in Mobile Development by gaurav
• 23,260 points
2,919 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