How to know if an Image is in memory in Flutter? - flutter

I have a screen in my app with an image as the background, this image is on my asset folder. When I navigate to this screen the background is blank for an instant and then the image is loaded and it appears. This makes my screen look weird for a half a second or less, but enough for the user to notice.
I wanted to be able to only navigate to that screen once the image is loaded (I can wait on the previous screen), so I can avoid this behavior and have the screen as a whole when the user navigates there.
I know can make the image fade in, but that's not the experience that I want.

You need to use ImageProvider.resolve method
So suppose you have some image registered in you assets.
Then you may obtain the image provider as
_imageProvider = Image.asset("your_asset").image.
Then you may add such method:
import 'dart:ui';
Image _image;
bool _resolved;
void _resolveImageProvider() {
ImageStream stream = _imageProvider.resolve(createLocalImageConfiguration(context));
stream.addListener(ImageStreamListener((info, _) {
setState(() {
//here you may set some flags or anything which indicates the image is in memory now.
_resolved = true;
_image = info.image;
});
}));
}
Then you can call this method on the "previous screen", wait till the listener is triggered and only then navigate to the next view.

Related

Unity 2D Button-Image color-swap causes image to disappear

I have a function ("ChangeAudio") wherein I toggle the sounds attached to it.
The audio toggling works fine, but I also have a button in the UI that when clicked, calls the audio toggle. Again this works fine. My problem is that when the audio is toggled I've added logic to swap the color of the buttons image to show a disabled state. The swap works, I can see it swap in the inspector, but the issue is that after the first click the image is no longer visible.
Here's the function:
public void ChangeAudio() {
Audio = !Audio;
if (Audio) {
soundIMG.color = enabled_color;
}
else {
soundIMG.color = disabled_color;
}
MM.AsDie.mute = !Audio;
MM.AsJump.mute = !Audio;
}
I hope that I've given all materials needed, if not please kindly let me know.
It looks like it should be working, why are the images disappearing?
Check alpha colors in the images

How to make pickedImage from gallery or camera to effect immediately to all the pages in flutter?

I picked the image from camera and gallery in the edit profile page and I need to make it effective to the dashboard and drawer of the app immediately and also when user closes his app and comes back the photo must be there in the app. How can I achieve this.
Now I will store the image in a variable of type File, but it doesn't effect immediately and also it collpases when app is closed.
The Image you are picking, store the image in a variable of type File in setState({}).
First, your problem is divided into two parts:
Once the image is picked, it should appear in the different
places in your app.
One way to do that using the provider package as state management. Then create a class that extends change notifier. after that define a function that updates the image and notifies listeners. Something like this
class YourClass extends ChangeNotifier {
String? _image;
String? get image => _image;
void updateImageAndSave(String providedImage) {
_image = providedImage;
saveTolocaleStorage(providedImage); //To save your image to any locale storage of your prefrence.
notifyListeners();
}
void updateImage(String providedImage) {
_image = providedImage;
notifyListeners();
}
}
Note I use string because I actually provide the path, not the image itself. but you can change that.
After that, you use the consumer widget right above anywhere you want to be updated once the updateImage() function is called.
Note the image is nullable so you need to check if the image is null to show your temporary widget(your placeholder).
Read the image from your local storage.
Once you have done the above part, read the image from your locale storage on the app startup. Then, update the image in your change notifier. This will display the image at all the different places you specified in your app

Load Data during Splash Screen in Flutter

I need to know is there any way to perform a task during splash screen is visible in flutter. I know how to add splash screen in flutter but I don't know how to perform background operations during splash screen is visible. I can't find anything on the internet, please help.
Yes, yes you can. The main() function can actually be tagged as async, so you can do whatever you need to do before running runApp(...) in the main() method body, even asynchronously. This way, the splash screen will be shown until your asynchronous result is retrieved, before calling runApp(...). For example:
Future<void> main() async {
// Do whatever you need to do here
final home = await setHomeWidgetDependingOnLoginStatus();
return runApp(MyApp(home: home));
}
The animated_splash_screen package does this worderfully. add it to your pubspec.yml
animated_splash_screen: ^1.1.0
AnimatedSplashScreen.withScreenFunction(
splash: 'images/splash.png',
screenFunction: () async{
// Your code here
return MainScreen();
},
splashTransition: SplashTransition.rotationTransition,
pageTransitionType: PageTransitionType.scale,
)
This will load and hold you splash screen until your function is complete.
Your function has to return a widget, in this case is your home screen. This also allows for dynamic routing depending on your data eg, is user logged in.

Open File Picker in snap view of Metro Style App

When I try to open file picker on snap view in Metro Style App, exception occurs and exception dialog box was shown. How to solve that problem? Is there any good idea? I want my app works properly even on snap view.
Before opening the file picker, you must try to leave the snapped mode.
Here is the code I use:
var ready = true;
if (ApplicationView.Value == ApplicationViewState.Snapped)
ready = ApplicationView.TryUnsnap();
if (!ready)
return;
The SDK samples available on msdn use the following snippet
// FilePicker APIs will not work if the application is in a snapped state.
// If an app wants to show a FilePicker while snapped, it must attempt to unsnap first
bool unsnapped = ((ApplicationView::Value != ApplicationViewState::Snapped) || ApplicationView::TryUnsnap());
if (!unsnapped)
{
// Unsnapping failed
}

Titanium: Youtube video

How can I show a youtube or bits on the run video full screen on my app? Is there a special link I have to naviate to? Or is there a special API that takes care of that to view it fullscreen?
The idea is to click on a link 'show video', then show the video fullscreen, and get a button play pauze and 'done'. When clicked done it goes back to the previous page.
I don't know how to get started on this one. Can anyone help me out?
I'm creating an iPhone app.
Thanks!
#Muhammad has the first part right but to get it to close when you hit the blue done button you'll need the following code.
replace
win.add(activeMovie);
activeMovie.play();
with
win.add(activeMovie);
activeMovie.fullscreen = 1; // this must be defined after you add to the window!
activeMovie.play();
then add this
activeMovie.addEventListener('fullscreen', function(e) {
if(!e.entering) { // this is run only when exiting fullscreen aka the blue done button
activeMovie.stop();
}
});
Here is a an example code to show video with controlls
var win = Titanium.UI.currentWindow;
var contentURL = 'http://movies.apple.com/media/us/ipad/2010/tours/apple-ipad-video-us-20100127_r848-9cie.mov';
var activeMovie = Titanium.Media.createVideoPlayer({
contentURL: contentURL,
backgroundColor:'#111',
movieControlMode:Titanium.Media.VIDEO_CONTROL_DEFAULT,
scalingMode:Titanium.Media.VIDEO_SCALING_MODE_FILL
});
win.add(activeMovie);
activeMovie.play();
Hope this will help.