I want to open progress dialog by the onclick event. When I click on the button, the dialog is not opened until all async methodes finished. So I want to open the dialog when it begin writing the file. someone any idea how to fix it?
Html
<buton onclick="writeFile"></button>
TS
public async writeFile() {
const dialogRef = this.dialog.open(ProgressComponent);
await this.writePage1()
await this.writePage2()
await this.writePage3()
await this.writePage4()
}
For somone that has the same issue here How I fixed it. you can use afterOpened() from the dialog to let first the dialog open and run the async methodes.
this.dialog.open(ProgressComponent).afterOpened().subscribe(() => {
await this.writePage1()
await this.writePage2()
await this.writePage3()
await this.writePage4()
});
Related
I'm facing with an issue that my files are not being uploaded to website, here is a code:
await mainPage.clickElement('locator for the element "Add logo"');
page.on('filechooser', async (fileChooser) => {
await fileChooser.setFiles('path to jpg file');
});
I'm using "#playwright/test": "^1.19.2",
why it is not working, what's wrong?
Here is a DOM:
https://i.stack.imgur.com/73Q48.png
UPD:
await mainPage.clickElement('locator for the element "Add logo"');
is a simple page.click(), just used from PageObject
You are having a race condition. I recommend using the waitForEvent function instead:
const [fileChooser] = await Promise.all([
page.waitForEvent('filechooser'),
page.click('locator for the element "Add logo"'),
]);
await fileChooser.setFiles('path to jpg file');
I am working on this Flutter app and I have implemented Firebase Cloud Messaging. I added the following code to make sure I can use the Shared Preferences package. It seems to work, but the functionality does not work correctly.
Extra configuration code
if (Platform.isAndroid) SharedPreferencesAndroid.registerWith();
if (Platform.isIOS) SharedPreferencesIOS.registerWith();
The backgroundhandler in action
Future<void> backgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
if (Platform.isAndroid) SharedPreferencesAndroid.registerWith();
if (Platform.isIOS) SharedPreferencesIOS.registerWith();
print("App is in background: Message received ");
final prefs = await SharedPreferences.getInstance();
final listOfTopics = prefs.getStringList('out_of_stock_topics') ?? [];
String topic = 'default_topic';
if (listOfTopics.contains(topic)) {
listOfTopics.remove(topic);
await prefs.setStringList('out_of_stock_topics', listOfTopics);
}
}
The code above deletes the topic in the list. Then the list is set with prefs.setStringList. I checked, and the code goes into the if statement. It removes the item from the list. But something goes wrong in prefs.setStringList I suppose.
Because later I use the following code to check the items in the 'out_of_stock_topics' list.
Code to check list of topics
final prefs = await SharedPreferences.getInstance();
final listOfTopics =
prefs.getStringList('out_of_stock_topics') ?? [];
print(listOfTopics);
But the topic is not correctly deleted and is still there. I think there is something wrong in the backend of the backgroundhandler. I tested this feature with 2 buttons: "add topic" and "delete topic". And with those separate buttons it does delete the item from the 'out_of_stock_topics' list.
Does anyone know how to fix this problem?
Thanks!
I am trying to get user email,save to shared preferences and use as collection name in another file.
my code to save
Future<void> saveEmail() async {
var sharedPreferences = await SharedPreferences.getInstance();
sharedPreferences.setString("email", _emailKontroller.text);}
no problem here, I can save data to sharedPreferences and read data from another file.
my code to read
#override
void initState() {
// TODO: implement initState
void initilaizeEmail() async {
var sharedPreferences = await SharedPreferences.getInstance();
_email = sharedPreferences.getString("email");
print(_email);
}
initilaizeEmail();
setState(() {});
}
output
I/flutter ( 3274): a#a.com
where I use as parameter my sharedPreferences Data:
query: FirebaseFirestore.instance
.collection("test")
.doc("$_email")
.collection("class 0"),
// to fetch real-time data
isLive: false,
I can not see anything on screen but, if I delete
_email
and type "a#a.com" manually everything works.What is the problem?
The problem is that initilaizeEmail is an async method, and you're not waiting for its result. To fix this:
await initilaizeEmail();
I also recommend fixing the name of the method to be initializeEmail. While it won't change the behavior, spelling mistakes tend distract from other problems.
I solved my problem with using
Future Builder
I am implementing a chat application where users can share images. Each image is a stateful widget and each of them should get uploaded to the Firebase Storage as well.
My problem is, this flow works fine at the beginning of the app but when you upload another image, instead of the a single file, now 2 files are getting uploaded (1 new file and the file from the previous message).
I am pretty sure that this is something to do with keys so I provide an instance of UniqueKey as well but the problem is still there.
Let me explain my implementation and then provide the code:
I have 2 files; one is the chat screen, and the other one is a single message chip.
Chat screen keeps a list of message chips and does the rendering accordingly.
Message chip is stateful because, I want the user to see a progress while it is being uploaded to the server. After picking up a file from the device, an instance of message chip will get pushed to the array in the chat screen.
My code for the attach pic button in chat screen:
IconButton(
icon: Icon(Icons.attach_file),
onPressed: () async {
final File _file = await ImagePicker.pickImage(
source: ImageSource.gallery);
if (_file != null) {
//appending to the messages list
final sss = new MediaMessage(
key: UniqueKey(),
file: _file,
isImage: true,
threadId: widget._threadId,
);
setState(() {
_messages.add(sss);
});
}
},
)
and here is the code in my message chip file (including only the essentials)
void initState() {
super.initState();
//creating a file name eg: img_456985.jpg
final rand = Math.Random().nextInt(10000);
final fileExt = widget.file.path
.substring(widget.file.path.lastIndexOf('.'), widget.file.path.length);
_fileName = 'image_$rand$fileExt';
final StorageReference storeRef = FirebaseStorage.instance
.ref()
.child('threads')
.child(widget.threadId)
.child(_fileName);
final uploadTask = storeRef.putFile(widget.file);
uploadTask.events.listen((event) {
setState(() {
_uploadPercentage = event.snapshot.bytesTransferred.toDouble() /
event.snapshot.totalByteCount.toDouble();
});
print(_uploadPercentage);
});
uploadTask.onComplete.then((snapshot) {
setState(() {
_uploadStatus = UploadProgressStatus.complete;
});
});
}
Here is a demo GIF of this issue:
GIF image demo
Any suggestions/solutions would be appreciated.
Thank you
Null the file value after image uploading task might work.
like
widget.file=null
place it after uploadTask
I am using Apify's puppeteer to login to this website. I did research similar questions but to no avail.
I am having trouble finding the clickable id/element for the main Login button seen on the linked login page. Currently, my code reads like this:
const Apify = require('apify');
Apify.main(async () => {
const input = await Apify.getValue('INPUT');
const browser = await Apify.launchPuppeteer();
const page = await browser.newPage();
await page.goto('https://www.sunpass.com/vector/account/home/accountLogin.do');
// Login
await page.type('#tt_username1', input.username);
await page.type('#tt_loginPassword1', input.password);
await page.waitFor(2000);
await page.click('#entryform input');
await page.waitForNavigation();
// Get cookies
const cookies = await page.cookies();
// Use cookies in other tab or browser
const page2 = await browser.newPage();
await page2.setCookie(...cookies);
await page2.goto('https://www.sunpass.com/vector/account/transactions/webtransactionSearch.do'); // Opens page as logged user
await browser.close();
console.log('Done.');
With the id entryform I receive the following error: Node is either not visible or not an HTMLElement
With the id loginP I receive the following error: No node found for selector
I used XPath to locate these, it offered no other ids of use. Any help would be greatly appreciated on how to find a clickable element for this login button, or any other method.
You have to try another selector.
I tried button[name="btnLogin"] and it worked.
tested code:
const Apify = require('apify');
Apify.main(async () => {
const input = await Apify.getValue('INPUT');
const browser = await Apify.launchPuppeteer();
const page = await browser.newPage();
await page.goto('https://www.sunpass.com/vector/account/home/accountLogin.do');
// Login
await page.type('#tt_username1', input.username);
await page.type('#tt_loginPassword1', input.password);
await page.waitFor(2000);
await page.click('button[name="btnLogin"]');
await page.waitForNavigation();
// Get cookies
const cookies = await page.cookies();
// Use cookies in other tab or browser
const page2 = await browser.newPage();
await page2.setCookie(...cookies);
await page2.goto('https://www.sunpass.com/vector/account/transactions/webtransactionSearch.do'); // Opens page as logged user
await browser.close();
console.log('Done.');
});
During my test of the login form on a desktop the "LOGIN" button could be found with this selector:
button[name=btnLogin].btn-large