Can you do me a script for Flutter photo access permisson? - xcode

This is a sample of my Flutter source code which controlled behavior of photo access permisson:
class __ImageWidgetState extends State<_ImageWidget> {
Future<bool> requestGalleryPermission() async {
const Permission _photos = Permission.photos;
final PermissionStatus permissionss = await _photos.request();
if (permissionss == PermissionStatus.granted) {
return true;
} else {
return openAppSettings();
// return false;
}
}
With this code, if users press Don't Allow they will be redirected to Photo Setting automatically.
I have changed openAppSettings() by false so nothing happens if users press Don't Allow, but they can't upload image until they go to Photo Setting to choose Allow manually.
I'm new to Flutter, so can you please help me with my below scritp?
Users pressing Don't Allow will see a popup saying that: Because you choose Don't Allow so you won't be able to change profile image and upload image.
They press OK button to close this popup. Everytime they want to change/upload image they will see popup which requires access photo again.
Thank you! I'm so grateful to you!

If the user don't allow the access for photos you can show an AlertDialog.
https://api.flutter.dev/flutter/material/AlertDialog-class.html
If it is allowed you just ask for permission again.

Related

How can I disable and enable a resource route Link in remix-run

Is there a way to disable a Resource route link while the resource is being generated and enabling it after that?
I have a PDF report that gets generated as soon as the user clicks on a Link. So I'm using a resource route that returns the PDF as a ReadableStream with a content-Disposition of attachment.
Here's a a code fragment example:
export const loader: LoaderFunction = async ({ params }) => {
invariant(params.recordID, "Record Id is required!");
let recordID = params.recordID;
let reportsService = createReportsService();
let reportFileStream = await reportsService.getReport(
recordID
);
return new Response(reportFileStream, {
headers: {
"Content-disposition": `attachment; filename=report.pdf`,
"Content-Type": "application/pdf",
},
});
};
I'm using the Link to the resource route this way:
<Link to={reportUrl} reloadDocument >
Get the Report
</Link>
I want the Link to get disabled as soon as the user clicks on it and then re enable it after the report is ready and the user has saved it (or discarded the "save" window).
I can't use useTransition hook because reloadDocument disables javascript behavior but I can't find out another way to disable and enable the link.
I can only disable it as soon as the user clicks on it (with a conditional pointer-events style controlled by useState) but I haven't found a way to detect when the report has been generated and the user has saved it (or discarded the "save" window) so I can re enable the link again.
So any help or hint to find a solution is very much appreciated!

Let user select a photo from a gallery

After going over ANY option possible, I can't find a solution to a simple problem :
Letting a user select a photo from a large gallery and save it to collection.
Like an image picker, you pick an image from a gallery and the window is closed.
No photo selection option on "user input" menu.
No way to connect any gallery including Wix Gallery to a data set as INPUT.
3rd apps let you do that but it's being saved in their own servers, and its limited to just a few photos, not to a large set
We basically have more than 100 photos in an album that a user should be able to somehow pick.
Another option is to open some kind of window with Pinterest stream and collect the URL of a selection, which also seems impossible.
There is no built-in image picker, but you can roll your own with a bit of code.
Here's a bit of code that should get you started in the right direction:
import wixData from 'wix-data';
import wixUsers from 'wix-users';
$w.onReady(function () {
$w('#gallery').clickAction = "none";
$w("#gallery").onItemClicked( (event) => {
let imageSrc = event.item.src;
let toInsert = {
"user": wixUsers.currentUser.id,
"image": imageSrc
}
wixData.insert("SelectedImages", toInsert)
.then( () => {
$w('#gallery').hide("fold");
} );
} );
} );
This code assumes you have a collection where you want to store "selected" images. That collection has at least two fields that have the following keys: user and image.
When an image in the gallery is clicked an event handler gets the src of the image and inserts it into the collection along with the current user's ID. Then the gallery is hidden.
All of the above can be customized to fit your specific situation, but this should give you an idea of what can be done.

How to know when Recaptcha window is closed

I'm facing the following situation: When an user clicks a submit button, the app disables the button. Then, when the callback function of the ReCaptcha is called, I can enable the button again. But if the user closes the verify window how can I know that and then enable my button again?
I was facing the same problem using invisible recaptcha. The way I solve it is observing when the captcha was getting closed.
First get the div Element containing the captcha.
let iframe = document.querySelector('iframe[src^="https://www.google.com/recaptcha"][src*="bframe"]');
let container = iframe.parentNode.parentNode;
Then
let observer = new MutationObserver( mutations => {
if(container && container.style.visibility === 'hidden'){
// Re enable the button
}
});
observer.observe(container, { attributes : true, attributeFilter : ['style'] });

How to get handle of popup window (WebdriverIO)

I am very very new to automated testing and I am currently completely stuck with the following issue:
I have a webpage open(first window)
In the same test I call a .newWindow(second window) and do some stuff in that window. The last action opens new popup window(popup window).
What I need, is to set the focus on a popup window.
According to WebdriverIO API I can use .switchTab http://webdriver.io/api/window/switchTab.html
But to be able to switch to a popup window I have to indicate handle, but I don't understand how to get the handle of a popup window :(
That s my piece of code:
//this is the part where I have already second window open
it('should open email letter', function(done) {
client
.pause(2000)
.clickAndWait('[title="Password restore"]', 4000)
.clickAndWait('[title="Restore password"]', 7000) //this is the part where popup window opens
.pause(2000)
.windowHandles(function(err,res){
console.log(res, handles)
}) // I have got three handles but i dont know how to use them now
.........
There is a lot of examples in java, but i didnt find anything that would fit mine language.
Please, excuse me my dumbness, I am really a very beginner and I will appreciate if somebody could explain that to me.
Thanks a lot in advance!
we not use getCurrentTabId to remember the handle of the currently open window?
For example:
var main, popup; //your window handles
client
.getCurrentTabId(function (err, handle) {
main = handle;
})
.newWindow('http://localhost:9001/') //you are on popup window
.getCurrentTabId(function (err, handle) {
popup = handle;
})
.switchTab(main) //you are back to main window
.switchTab(popup) //you are on popup again
.close(popup) //extra bonus!
I notice you stated "The last action opens new popup window(popup window). What I need, is to set the focus on a popup window."
I had this issue. But the new window was opened when clicking on login with facebook. This caused an issue on finding the handle for the new window because I could not use .newWindow('http://localhost:9001/'). The API keys and all sorts are added as parameters when using a social login. So one has little control
To handle this I registered each window ID as its opened.
The first background step in my feature is Given I open the url "/a.html"
In the step you can set an empty array as the variable windowID with let let windowID = []
So my step file would look like this
const url = 'http://localhost:8080'
let windowID = []
this.Given(/^I open the url "([^"]*)"$/, (path) => {
browser
.url(url + path)
console.log(`# Navigating to ${url + path}`)
expect(browser.getUrl()).toEqual(url + path)
windowID.main = browser.getTabIds()
});
During the step after clicking the Facebook button you can then check all the open window ID's and drop the one that matches windowID.main
this.When(/^I authenticate with facebook$/, function (arg1) {
// log the ID of the main window
console.log('Main Window ID' + windowID.main)
browser
.pause(2000)
.getTabIds().forEach(function (value) {
if (value === windowID.main) {
// we do not need to do anything with windowID.main as it's already set
return
}
// if the value does not match windowID.main then we know its the new facebook login window
windowID.facebook = value
})
// log both of these
console.log('Main Window ID: ' + windowID.main)
console.log('Facebook Window ID: ' + windowID.facebook)
// Do the login
browser
.switchTab(windowID.facebook)
.setValue('input[name="email"]', process.env.FACEBOOK_EMAIL)
.setValue('input[name="pass"]', process.env.FACEBOOK_PASSWORD)
.submitForm('form')
});
note that I add credentials as an environment variable. This is a good idea, you don't want to commit your personal credentials to the code base. One may think well obviously, but you may not, who knows.
You had your question answered years ago, but I found this post first when trying to find a solution so it seems a sensible place to put this addition.

On Session Timeout Login.gsp is rendered within the <body> tag instead of redirecting to a new gsp page

I am new to Grails and working on a project which has just 2 controllers one is for login and the other is for a explorer (similar to a windows explorer with left panel displaying a tree -like structure and the right displays the folders contents as a table)
The application is working as excpected meaning when user accesses the application it displays Login Screen if user hasn't logged in and if he has logged in it displays the explorer screen.
But this is not the case on session Timeout: suppose the session has timed out and the user clicks on a link in the right panel of the explorer screen then the login screen is displayed within the right panel.
I am using SecurityFilter to redirect to login screen.
SecurityFilters.groovy
def filters = {
loginCheck(controller:'*', action:'*') {
before = {
if (!session.idpuser && actionName != "login") {
redirect(controller: "user", action: "login")
return false
}
}
}
}
userController.groovy
def login () {
if (request.get) {
return false
}
......
redirect(controller: "explorer", action: "file")
}
explorerController.groovy
def generateFiles = {
.....
render(template: 'list', model: [ dirList: dirList])
}
UrlMappings.groovy
static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(action:"file", controller: "explorer")
"500"(view:'/error')
}
The reason I think login.gsp is being rendered in the right panel is because when a user click on a link in right panel "generateFiles" action is invoked and that is rendering login.gsp as a template within explorer.gsp. But I dont know how to fix it :(
I would appreciate if someone can help me with this issue.
PLEASE HELP!!!!!
Since this is an ajax based site, you need to explicitly handle the "you need to login" response in your ajax response handlers and force the user to the login page if needed.
Looks like I found the solution may not be an efficient way but it works.Based on the response I get from the Ajax call I am redirecting to Login.gsp using
window.location.href = '${createLink(controller='user', action='login')}'
Thank you cdeszaq for the hint. I really appreciate it.

Resources