Flutter: How to show splash screen based on theme data saved using shared preferences? - flutter

Currently the splash screen is showed according to the device theme and rest of the app according to user selected theme, but I want to show the splash screen according to the selected theme by the user (which I do save in shared preferences).

It's not possible.
Splash screen is handled by the system, and you app isn't launched yet, so no code to load user preferences could be run.

Uh, technically it's possible.
Here's a high-level overview:
You can always show a blank Container() on opening your app, while in the meantime you have your SharedPrefs checking the saved theme/appearance, then, once you have that data, you can show a splash screen where the rest of your prefs then load.
While at first glance this may seem inefficient, the call to SharedPrefs is so fast users literally won't notice that there was a frame of a blank screen before the Splash Screen comes up.
Source: Implemented this for my team's app and it works beautifully.

Related

Flutter return a screen that has previous screens pushed into its navigator

I have the following situation:
I have an onboarding user flow that consists of lets say 5 screens where the user provides some personal details on each screen, the details are persisted into the database after each screen and then the user is taken into the home screen.
Desired behaviour:
When the user provides detalis until e.g. screen 3/5 and then exits the application, the flow should resume from screen 3/5, with the posibility to return back to screens 1 or 2 to change the already provided details.
I couldn’t find anything in the navigator documentation that would help me, and if you could provide at least a documentation lead for this edge case it would be amazing.
Basically I need to restore the stack of screens “in the background” when the user re enters the app and “show” the stack from the screen i/n (where i is the first screen where the user did not provide details in the last session) with the possibility to navigate back in the stack to the screens before i even if those screens were not shown to the user in the current session.
Or even more simply put, I need to restore a stack of screens in a new app session and show the user a screen from any position of the navigator stack based on data persisted on a db.
Thanks!
You can use PageView widget from flutter for your onboarding process, that way you can save on which page user was by the database entries, and you can directly jump on the specific page you want by the index. That way you don't have to worry about navigating through the screens.
Here's the link for PageView Widget implementation: https://www.geeksforgeeks.org/pageview-widget-in-flutter/
Well I think first you need to store the data the user already entered and the screen number he was on. You can use something simple as shared_preferences.
Then you have to use routes to navigate to a specific screen.

how to remove flutter's default splash screen?

I'm a developer who is developing a flutter.
I have a question about the default splash screen of the flutter.
I found that the first time I created the flutter project, it basically included a splash screen with a flutter icon.
I looked it up to erase the default splash screen, but I got a reply that it is not possible in the flutter/dart stage.
To solve this problem, first of all, I wanted to customize the defalut splash screen using the flutter_native_splash library.
However, the library did not meet my requirements because it was impossible to insert elements other than images (ex. text).
So, I used the flutter_native_splash library to insert an icon with only pure white color to create a fake splash screen.
And I made a real splash screen, registered it as the initial screen of the GetX library, and set it up to move on to the next page after the schedule delay.
You can check the ones described above in the video below.
In this situation, I have two questions.
First, I wonder if I can insert text into the splash screen using the flutter_native_splash library.
Secondly, I wonder if there is a way to delete the default splash screen that is automatically generated by the flutter.
The default splash screen cannot be overridden with Dart/Flutter alone. They are controls shown by the native Android/iOS context while the Flutter runtime is initializing. As such, any splash screen widget you create inside Flutter will show after the default splash screen. (Even if you completely remove the default splash image, the app would just be a blank while screen until Flutter finished loading, and that's bad design.)
There are instructions on how to change the default splash screen here :
For Android
Step 1: Go to android/app/src/main/res/drawable folder :
Here you will find a file launch_background.xml. This is where you can write some code and make it work.
Step 2: Open launch_background.xml
Step 3: Change Background
Uncomment line 7–11 and this is where you can change your background, maybe a color or image on line 4
<item android:drawable=”#color/ic_launcher_background” />
Step 4: Change Image/Icon
This is where (on line 10) you can change your app icon or to an image which will be in the center if android:gravity is center (Make sure you add your icons for different size devices for better result).
android:src=”#drawable/qart_trans”
And That’s it!! Woohoo
For iOS
Step 1: Open the project in iOS stuff in XCode
Step 2: Go to ios/Runner Folder
You will see here Assets.xcassets folder and LaunchScreen.storyboard. These are two things which we want.
Step 3: Open Assets.xcassets and click on LaunchImage
Paste your images/icons in 1x 2x 3x Options according to recommended sizes for devices
Step 4: Now Open LaunchScreen.storyboard
Click on the view and on the right panel click the down arrow like symbol change properties like background and content mode according to your need.
Step 5: Now Click the Image on the storyboard
Now on the right panel click the down arrow like symbol gain and change its properties as per need.
And That’s it again!! Voila!!!

Is there a way to save state in Flutter so the App starts off from where we left off?

I want data to be persistence. I want the state to be same from where I left off before closing the app. Is there a way to achieve this in flutter?
I dont know this is the right solution for this, but maybe you can save the last pages path to sharedpreferences every time user navigates to a page, then when your app is opening, read the last page from shared preferences and navigate to that page.

Conditional Activity Start

I want to start the application by giving the user to disable/enable the Splash Activity at start.
I created a activity without layout and decided to load the splash activity or directly goes to main activity based on SharedPreference setting that user saves.
The concept works fine but the startup activity shows for a very short time before it switches to Splash or Main activity.
How can I resolve that?
Any other way that I can achieve this?
Thanks for not answering me at all!!!!
I just found that, If I make a decision on Splash Activity itself, it works fine.
In fact, On Splash Activity itself, if the SharedPreference lookup returns the True, it shows the Splash activity itself and if not, it goes to Main Activity by running the intent.
That works fine

Splash screen should check data from database

hi i am creating an map application ,
initially when i click on the application icon on iphone a Splash screen showing application logo and a loading bar should be shown.
Expected Process:
Screen should achieve following objectives of initialization
1.Initialization of Synchronization Web Service
2.Create or Open available database on the device and keep the referece in the memory for quicker calling.
3.Validation of available UserInformation Record in database
4.Build up a Weather Map which should hold all 37 types of weather available for easy future reference
On each processing step progress bar should grow/fill with 25%
How could this be possible.Please anybody help me in achieving this tasks
The splash screen is just an image that should be called default.png. It will display during the launch of you app.
To realize what you want you have to define the first view controller with the same background and a UIProgress and do your sync and other processes.
When initialization is done you have to display your "real" first view controller
When user launch the application you could show a splash screen for 1 or 2 second after that you could show the progress (status) of your application using text msg.
for example "Initialization of Synchronization Service" ,"Storing to data base", "Loading map" .
The above text msg. is just a reference,you could have more descriptive text to show on screen along with progress bar.