Flutter: How to change theme from runtime? - flutter

I have 3 themes based on colours like a red theme, blue theme and a dark theme as well. I want to change the theme of the app while the app is running.
I want to show an alert dialog from where the user can select the color of the theme.

When you present an AlertDialog (using await showDialog()), there is a Future<dynamic> return value. So, have some buttons in the dialog that lets the user choose their theme. Once the user is done choosing the theme, return the chosen theme using Navigator.of(context).pop(selectedTheme).
Wait for this value wherever you're showing the dialog like final userSelectedTheme = await showDialog(...). Once you have the new value, then update whatever state model is holding the theme and your app should update accordingly.
Since themes are generally at the top-level of the app, you'll probably need something more than just stateful widgets if you aren't using anything else. I'd look into Provider if you aren't familiar with anything else:
https://pub.dev/packages/provider

Related

How to change the primary colour of a theme on button press in flutter?

I have set the theme properties properly in the app. I am trying to give the user the freedom to change colour of the app (primary colour) as the user wishes. I tried implementing state management on the "main.dart" file but once the theme has been initialized in runApp, while the app is running it does not let me change the primary colour of the theme, only allows change of modes (light and dark). Is there a way to change the primary colour of a theme on button press?
I would have used something like this (to change primary color to green for example) :
Get.changeTheme(Get.theme.copyWith(primaryColor: Colors.green));
But it seems to raise an well known error (see : https://github.com/flutter/flutter/issues/103864)
i think you have to assign the color to provider and save it in the sharedprefrences after that you have to re-run the app and the theme from sharedpreferences

circular reveal theme switcher like telegram in flutter

I am using DayNight theme in my application. And I have a button that changes the theme. In Telegram app there is a beautiful reveal animation that changes the theme without restarting activity or something like that. How to achieve this in flutter? and also the theme change should be persistent using shared preference and provider.
i want to achieve something like this:-
Here is what you are looking for

Change Background Image in Flutter according to theme

I have different pages, and one FloatingActionBar, whensoever I am clicking on it, the theme of the application is getting changed. But I also want to change the background image of the app. How can I do that?

Customize the App Bar from the phone's opened apps menu with Flutter

I am making an app with Flutter and I want to change the text and the color of the bar that appears on the opened apps menu on the phone.
For example, in the linked image below, change the text from "Pokemon Go" to something else, and change the color from grey to blue.
https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSyrJhMbO_QCYgVxInVT1Ff1QuP_9aHAvClIg&usqp=CAU
You can acheive this by wrapping your root Widget with MaterialApp(); and specifying the title of the material app like:MaterialApp(title: "Paco") and specifing the primary color: MaterialApp(title: "Paco",theme: ThemeData(primaryColor: Colors.blue),);

How to change header text theme of time picker in flutter

Screen shot of time picker dialogue box
In default header text theme in time picker is primary color of theme data.
How can customize time picker of header text theme?
Thanks.
You need to use the copyWith of the current theme and change the specific property that you need here you can find more information about the copyWith method.
You can look here how to implement a change in certain change of the current theme.