flutter dark mode splash screen setting in pubspec - flutter

I use package splash_screen_view for my splash screen.
and it got the dark and light image for the default theme of the app.
but if the user theme mobile is light and wants to use the app dark, how can I set a condition for my splash?
the setting of this package sets In pubspec.yaml
so can anyone help me, please?
here is my pubspec:

Check that your MaterialApp() has theme and darkTheme set AND set themeMode: ThemeMode.system, so your app follows the settings of the user's phone.
Looks something like this:
MaterialApp(
title: 'Great App',
theme: lightTheme, //create this
darkTheme: darkTheme, //create this
themeMode: ThemeMode.system, //follows user's device setting
home: GoHome(),
);
Your splashscreen will follow the correct setting.
Bonus: Search for flutter_native_splash to ALSO set the native splashcolor to phonesetting.

Related

I see different font familiy when i upload to google play store

I use google_fonts in my flutter project. while i run the code, i can see my font settings in the app. but, when i upload my app to google play console, i cant see my font familiy settings, i see different font family. what is the problem?
static TextStyle styleGraphicBoldText = GoogleFonts.mali(
color: MainColor.mainColor,
fontSize: (AppConfig.screenHeight!) / 70,
fontWeight: FontWeight.bold,
);
home: HomePage(
prefs: prefs,
),
theme: ThemeData(
textTheme: GoogleFonts.maliTextTheme(Theme.of(context).textTheme)),
I tried to run flutter clean, changing version name. They didn't help
Google fonts uses internet, so you may have to update the dependencies in the manifest.xml file.
<uses-permission android:name="android.permission.INTERNET"/>
Else you can try to make the google font available in the offline by adding it in the assets folder.
MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
// textTheme: GoogleFonts.maliTextTheme(
// Theme.of(context).textTheme,
// ),
fontFamily:'maliTextTheme' <-- 👈 Use this code to load offline
),
home: GoogleFontDemo(),
);
Refer this : https://stackoverflow.com/a/74949875/13431819

Flutter how lo listen device dark theme change instantly

My flutter app doesnt listen user's preferences changes at dark theme feature. I need to hard restart my app to reflect the changes.
How to make my flutter theme change instantly once I turn on / off the dark theme in device setting?
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
brightness: Brightness.light
),
darkTheme: ThemeData(
brightness: Brightness.dark
),
themeMode: ThemeMode.system,
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
Thanks
I would recommend you give this plugin Adaptive Chameleon Theme a try. It is designed to help you switch theme modes with ease be it from light to dark or even utilising the default user defined device theme.
Like so:
// sets theme mode to dark
AdaptiveChameleonTheme.of(context).changeThemeMode(dark: true);
// sets theme mode to light
AdaptiveChameleonTheme.of(context).changeThemeMode(dark: false);
// sets theme mode to system default
AdaptiveChameleonTheme.of(context).changeThemeMode(dynamic: true);
It also comes with the added benefit of allowing you to change the theme colours if you need to.
AdaptiveChameleonTheme.of(context).setTheme(AppThemes.LightRed);
AdaptiveChameleonTheme.of(context).setTheme(AppThemes.LightBlue);
The selections are stored in shared preferences and persisted in the device memory.
Full disclosure, I am the developer of the plugin so you can consider this a shameless plug. However, I too faced similar challenges in the past leading me to develop this quick and easy to use solution.
To see the change you need two things, use StatefulWidget and call setState everytime user change theme.
IconButton(
onPressed: () {
setState(() {
functionToChangeTheme();
});
},
icon: Icon(Icons.add),
)

Why my status bar icons are black and why can't I change it? (After Flutter 2.0 Upgrade)

After I upgrade Flutter 2.0, the color of the status bar's icon/text changed from white to black. After I upgraded because I did not make any other changes. Now the status bar icons of all apps I run is black. Why?
I tried the real device. Result is the same. So this is not an emulator problem.
Also not working Brightness.light:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarIconBrightness: Brightness.light,
));
When I run this code, it turns white for a few seconds and then turns black again. Like here:
I wonder if people who have upgraded after Flutter 2.0 have the same problem?
What is the reason for this and how to make white again?
Edit: When I flutter downgrade it turns white. The problem seems to be with flutter upgrade to 2.0. But this time when I run statusBarIconBrightness: Brightness.dark it goes black for a few seconds and turns white again. This code doesn't work at all. So Flutter 2.0 is not the reason why I can't change it to white when it is black. But the reason it's black is flutter 2.0.
Try this
MaterialApp(
//...
theme: ThemeData(
//...
appBarTheme: AppBarTheme(brightness: Brightness.dark),
),
//...
)
it's a bug, I saw somebody created an issue on flutter repo
meanwhile this code does fix an issue:
appBar: AppBar(
brightness: Brightness.dark,
),
Try this out:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light)
Found a solution to this. brightness: Brightness.dark;
AppBar(
title: Text(widget.title),
backgroundColor: Constants.appBarColor,
brightness: Brightness.dark;
centerTitle: false,
elevation: 4.0,
);
So Brightness.dark makes status bar white.
If you're running the new Flutter SDK 2.5, then use
appBar: AppBar(systemOverlayStyle: SystemUiOverlayStyle.light,)
instead of "brightness: Brightness.dark" as it was deprecated

Flutter setting default font family for non-material apps

I want to use a default font family for my flutter app but according to the Flutter docs for setting a default font family we should declare it as a theme data in our MaterialApp instance
Text : To use a font as the default, set the fontFamily property as part of the app’s theme. The value provided to fontFamily must match the family name declared in the pubspec.yaml.
MaterialApp(
title: 'Custom Fonts',
// Set Raleway as the default app font.
theme: ThemeData(fontFamily: 'Raleway'),
home: MyHomePage(),
);
But I don't want to use MaterialApp for my app and I want to set a font as the default font of my application , any solution ?
No.
you can use your font anywhere that you want
Text("Helloo!",style:TextStyle(fontFamily:"font name"))

How to run a flutter app with iOS theme (look & feel, behavior)

I needed to see how my UI would look on an iOS device, while working with only android emulator. (a common case for Linux/Windows developers)
Wanted a switch I could set just for debugging.
Setting the platform property in the app's theme did the trick.
The important line: platform: TargetPlatform.iOS
MaterialApp(
title: 'app,
theme: new ThemeData(
primarySwatch: Colors.red,
platform: TargetPlatform.iOS, //Makes the UI look and feel like iOS
),
home: MyHomePage(title: 'app'),
)