photo_gallery plugin not get Media in isolate - multithreading

Hello friends!
i have a problem with photo_gallery plugin.
i need run below function in other isolate
var image = await _album.listMedia(
skip: 0,
take: 20,
newest: true
);
This code write by me
ReceivePort p = ReceivePort();
p.listen((message) {
// other codes
});
Isolate.spawn(loadContents, [p.sendPort, album, files.length]);
Isolate call below function
Future<List?> loadContents(List<Object> arguments) async {
SendPort p = arguments[0] as SendPort;
Album album = arguments[1] as Album;
int length = arguments[2] as int;
var listAlbum = await album.listMedia(
skip: length,
take: 21,
newest: true
);
Isolate.exit(p, listAlbum);
}
But i see below error message on console
E/flutter (12023): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Invalid argument(s): Illegal argument in isolate message: (object extends NativeWrapper - Library:'dart:ui' Class: Path)
E/flutter (12023): #0 Isolate._spawnFunction (dart:isolate-patch/isolate_patch.dart:399:25)
E/flutter (12023): #1 Isolate.spawn (dart:isolate-patch/isolate_patch.dart:379:7)
E/flutter (12023): #2 NavigationViewModel.addImagesInDatabase (package:smart_gallery/provider/notifier/navigation_viewmodel.dart:145:13)
E/flutter (12023): <asynchronous suspension
how i can use loadContents function in flutter isolate ?
Thank's in advance!

Related

TypeError: inspect(...).addField is not a function

var embed = new Discord.MessageEmbed()
.setColor('#f03824')
.setTitle('Evaluated')
.addField(`To Eval`, `\`\`\`${command}\`\`\``)
.addField('Evaled', `\`\`\`js\n${inspect(evaled, { depth: 0})}\`\`\``
.addField(`Type Of`, `\`\`\`${typeof(evaled)}\`\`\``))
message.channel.send(embed)
How do i fix this error?
TypeError: inspect(...).addField is not a function
You're missing a closing parentheses ) at the end of the line
.addField('Evaled', `\`\`\`js\n${inspect(evaled, { depth: 0})}\`\`\``
Add it and it should work:
.addField('Evaled', `\`\`\`js\n${inspect(evaled, { depth: 0})}\`\`\``)

TypeError: Cannot read property 'AccountToken' of undefined

Trying to run the following test for a select component that is being import 'react-select'
I have the click events running fine, but onChange event is displaying an error:
TypeError: Cannot read property 'Accounts' of undefined
Here is where the error is located, line :
setReport = () => {
let data = this.state.Account.accountBody;
this.setState({
AccountToken: data.AccountToken,
Render();
<Select
className={'field-input-select margin-right'}
id='accounts-id-test'
value={this.state.Account}
onChange={(e) => { this.setState({Account: e}, ()=>{this.setReport()}) }}
Using mount :
it("should check button click event - Select ", () => {
baseProps.onClick.mockClear();
wrapper.find('CLASS YOUR TESTING').setState({
contactOptions:[],
Account:[[""]],
accountOptions: [{ value: 'test', label: 'label test', accountBody: "test account" }],
showRequired: false,
loading:false
});
wrapper.update()
// wrapper.update()
wrapper.find('CLASS YOUR TESTING').find('Select').at(0).props().onChange({
contactBody:{
Accounts:[]
}})
onChange works at(0) and not at (1) . Why ?
The error means that:
let contactBody = contact.contactBody;
is undefined so now you should try to debug with console.log or other ways and see why it is undefined and find a Solution
Able to figure out
wrapper.find('CLASS YOUR TESTING').find('Select').at(1).props().onChange({
accountBody:{
LOA:{
Documents:{
Signers:[],
}
}
}
})

Bot framework (v4) Prompt choice in carousel using HeroCards not going to next step

I’m trying to use HeroCards along with a prompt choice in a carousel. So the options to be selected by the user are displayed as HeroCards. As soon as the user clicks in the button of a card it should goes to the next waterfall function.
Here is a working example in bot framework v3. It does work as expected.
const cards = (data || []).map(i => {
return new builder.HeroCard(session)
.title(`${i.productName} ${i.brandName}`)
.subtitle(‘product details’)
.text(‘Choose a product’)
.images([builder.CardImage.create(session, i.image)])
.buttons([builder.CardAction.postBack(session, `${i.id.toString()}`, ‘buy’)]);
});
const msg = new builder.Message(session);
msg.attachmentLayout(builder.AttachmentLayout.carousel);
msg.attachments(cards);
builder.Prompts.choice(session, msg, data.map(i => `${i.id.toString()}`), {
retryPrompt: msg,
});
Below I’m trying to do the same with bot framework v4 but it does not work. It never goes to the next function in my waterfall.
How can I do the same with v4?
…
this.addDialog(new ChoicePrompt(PRODUCTS_CAROUSEL));
…
const productOptions: Partial<Activity> = MessageFactory.carousel(
item.map((p: Product) =>
CardFactory.heroCard(
p.productName,
‘product details’,
[p.image || ''],
[
{
type: ActionTypes.PostBack,
title: ‘buy’,
value: p.id,
},
],
),
),
‘Choose a product’,
);
return await step.prompt(PRODUCTS_CAROUSEL, productOptions);
…
UPDATE:
Follow full code with the suggestion from #Drew Marsh
export class ProductSelectionDialog extends ComponentDialog {
private selectedProducts: Product[] = [];
private productResult: Product[][];
private stateAccessor: StatePropertyAccessor<State>;
static get Name() {
return PRODUCT_SELECTION_DIALOG;
}
constructor(stateAccessor: StatePropertyAccessor<State>) {
super(PRODUCT_SELECTION_DIALOG);
if (!stateAccessor) {
throw Error('Missing parameter. stateAccessor is required');
}
this.stateAccessor = stateAccessor;
const choicePrompt = new ChoicePrompt(PRODUCTS_CAROUSEL);
choicePrompt.style = ListStyle.none;
this.addDialog(
new WaterfallDialog<State>(REVIEW_PRODUCT_OPTIONS_LOOP, [
this.init.bind(this),
this.selectionStep.bind(this),
this.loopStep.bind(this),
]),
);
this.addDialog(choicePrompt);
}
private init = async (step: WaterfallStepContext<State>) => {
const state = await this.stateAccessor.get(step.context);
if (!this.productResult) this.productResult = state.search.productResult;
return await step.next();
};
private selectionStep = async (step: WaterfallStepContext<State>) => {
const item = this.productResult.shift();
const productOptions: Partial<Activity> = MessageFactory.carousel(
item.map((p: Product) =>
CardFactory.heroCard(
p.productName,
'some text',
[p.image || ''],
[
{
type: ActionTypes.ImBack,
title: 'buy',
value: p.id,
},
],
),
),
'Choose a product',
);
return await step.prompt(PRODUCTS_CAROUSEL, {
prompt: productOptions,
choices: item.map((p: Product) => p.id),
});
};
private loopStep = async (step: WaterfallStepContext<State>) => {
console.log('step.result: ', step.result);
};
}
PARENT DIALOG BELOW:
...
this.addDialog(new ProductSelectionDialog(stateAccessor));
...
if (search.hasIncompletedProducts) await step.beginDialog(ProductSelectionDialog.Name);
...
return await step.next();
...
MY BOT DIALOG STRUCTURE
onTurn()
>>> await this.dialogContext.beginDialog(MainSearchDialog.Name) (LUIS)
>>>>>> await step.beginDialog(QuoteDialog.Name)
>>>>>>>>> await step.beginDialog(ProductSelectionDialog.Name)
UPDATE
Replacing the ChoicePrompt with TextPromt (as suggested by Kyle Delaney) seems to have the same result (do not go to the next step) but I realised that if remove return from the prompt like this:
return await step.prompt(PRODUCTS_CAROUSEL, `What is your name, human?`); TO await step.prompt(PRODUCTS_CAROUSEL, `What is your name, human?`);
it does work but when I'm returning the original code with ChoicePrompt without return like this:
await step.prompt(PRODUCTS_CAROUSEL, {
prompt: productOptions,
choices: item.map((p: Product) => p.id),
});
I'm getting another error in the framework:
error: TypeError: Cannot read property 'length' of undefined
at values.sort (/xxx/Workspace/temp/13.basic-bot/node_modules/botbuilder-dialogs/lib/choices/findValues.js:84:48)
at Array.sort (native)
at Object.findValues (/xxx/Workspace/temp/13.basic-bot/node_modules/botbuilder-dialogs/lib/choices/findValues.js:84:25)
at Object.findChoices (/xxx/Workspace/temp/13.basic-bot/node_modules/botbuilder-dialogs/lib/choices/findChoices.js:58:25)
at Object.recognizeChoices (/xxx/Workspace/temp/13.basic-bot/node_modules/botbuilder-dialogs/lib/choices/recognizeChoices.js:75:33)
at ChoicePrompt.<anonymous> (/xxx/Workspace/temp/13.basic-bot/node_modules/botbuilder-dialogs/lib/prompts/choicePrompt.js:62:39)
at Generator.next (<anonymous>)
at /xxx/Workspace/temp/13.basic-bot/node_modules/botbuilder-dialogs/lib/prompts/choicePrompt.js:7:71
at new Promise (<anonymous>)
at __awaiter (/xxx/Workspace/temp/13.basic-bot/node_modules/botbuilder-dialogs/lib/prompts/choicePrompt.js:3:12)
this is the line:
// Sort values in descending order by length so that the longest value is searched over first.
const list = values.sort((a, b) => b.value.length - a.value.length);
I can see the data from my state is coming properly
prompt: <-- the data is ok
choices: <-- the data is ok too
Sometimes I'm getting this error too:
error: TypeError: Cannot read property 'status' of undefined
at ProductSelectionDialog.<anonymous> (/xxxx/Workspace/temp/13.basic-bot/node_modules/botbuilder-dialogs/lib/componentDialog.js:92:28)
at Generator.next (<anonymous>)
at fulfilled (/xxxx/Workspace/temp/13.basic-bot/node_modules/botbuilder-dialogs/lib/componentDialog.js:4:58)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
this line
// Check for end of inner dialog
if (turnResult.status !== dialog_1.DialogTurnStatus.waiting) {
You're using a ChoicePrompt, but when you call prompt you're only passing through an activity (the carousel). ChoicePrompt is going to try to validate the input against a set of choices that you should be passing in when you call prompt. Because you're not doing this, the prompt is not recognizing the post back value as valid and technically should be reprompting you with the carousel again to make a valid choice.
The fix here should be to call prompt with PromptOptions instead of just a raw Activity and set the choices of the PromptOptions to an array that contains all the values you expect back (e.g. the same value you set for the value of the post back button).
This should end up looking a little something like this:
Since you're providing the choices UX with your cards, you want to set the ListStyle on the ChoicePrompt to none
const productsPrompt = new ChoicePrompt(PRODUCTS_CAROUSEL);
productsPrompt.style = ListStyle.none;
this.addDialog(productsPrompt);
Then, set the available choices for the specific prompt:
return await step.prompt(PRODUCTS_CAROUSEL, {
prompt: productOptions,
choices: items.map((p: Product) => p.id),
});
Basically Drew Marsh was right.
I just would like to add some other details that I had to tweak to make it work. In case someone else is going crazy like I was. It could give some insights. It's all about how you handle the returns of nested dialogs.
First change. I had to transform the identifier of the Choice prompt into string:
{
type: ActionTypes.PostBack,
title: 'buy',
value: p.id.toString(),
},
and
return await step.prompt(PRODUCTS_CAROUSEL, {
prompt: productOptions,
choices: item.map((p: Product) => p.id.toString()),
});
Another problem that I found was in the parent dialog:
I was basically trying to do this:
if (search.hasIncompletedProducts) await step.beginDialog(ProductSelectionDialog.Name);
return await step.next();
Which makes no sense, then I changed it to:
if (search.hasIncompletedProducts) {
return await step.beginDialog(ProductSelectionDialog.Name);
} else {
return await step.next();
}
And then the final change in the parent of the parent dialog:
Before was like this:
switch (step.result) {
case ESearchOptions.OPT1:
await step.beginDialog(OPT1Dialog.Name);
break;
default:
break;
}
await step.endDialog();
Which again does not make sense since I should return the beginDialog or endDialog. It was changed to:
switch (step.result) {
case ESearchOptions.OPT1:
return await step.beginDialog(OPT1Dialog.Name);
default:
break;
}

adding listview.builder inside row giving an exceptions

when I try to add an listview.builder inside a row an exception appears
my code:
return new Scaffold(
appBar: new AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: new Text(widget.title),
),
body: Row(children: <Widget>[
ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: 3,
itemBuilder: (BuildContext context, int index) {
return Text('data');
},
)
// This trailing comma makes auto-formatting nicer for build methods.
],)
);
the exception:
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 5949): The following assertion was thrown during performLayout():
I/flutter ( 5949): 'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1597 pos 16:
I/flutter ( 5949): 'constraints.hasBoundedWidth': is not true.
I/flutter ( 5949): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 5949): more information in this error message to help you determine and fix the underlying cause.
Wrap Expanded and then add to list.builder > physics:
const NeverScrollableScrollPhysics(),

Subquery returns more than one row? Can't write in database

I have a problem with my PHP-Script. I want to insert data into my database but the only thing it returns is an Error.
Code:
<?php
require_once('ConnectionHandler.php');
Class CreateTask
{
public function createNewTask($description, $subject, $type, $enddate, $priority)
{
$query = 'INSERT INTO task (description, subject_id, task_type_id, enddate, priority) VALUES (?, (SELECT id_subject FROM subject WHERE name = ?), (SELECT id_task_type FROM task_type WHERE type = ?), ?, ?)';
$statement = ConnectionHandler::getConnection()->prepare($query);
$statement->bind_param('siisi', $description, $subject, $type, $enddate, $priority);
if (!$statement->execute()) {
throw new Exception($statement->error);
} else {
return true;
}
}
}
?>
In the ConnectionHandler it set up the Connection to the database.
Error:
Fatal error: Uncaught exception 'Exception' with message 'Subquery returns more than 1 row' in E:\xampp\htdocs\lib\CreateTask.php:16 Stack trace: #0 E:\xampp\htdocs\homelogedin.php(21): CreateTask->createNewTask('fgdgdsg', 'Mathematics', 'Exam', '2015-05-31', '3') #1 E:\xampp\htdocs\pages\index.php(4): require_once('E:\\xampp\\htdocs...') #2 E:\xampp\htdocs\lib\CentralDesign.php(35): require_once('E:\\xampp\\htdocs...') #3 E:\xampp\htdocs\index.php(9): CentralDesign->loadPage() #4 {main} thrown in E:\xampp\htdocs\lib\CreateTask.php on line 16
You just can't use INSERT INTO that way. Subquerys are not allowed in this context. But scalar expressions will to the trick:
INSERT INTO task (description, subject_id, task_type_id, enddate, priority)
SELECT 'desc', A.id_subject, B.id_task_type, '2015-05-05', 2
FROM
(SELECT id_subject FROM subject WHERE name = 'Blau') A,
(SELECT id_task_type FROM task_type WHERE type = 'typ1') B
Best regards, binzram
PS:
Next time take the lil journey to my desk.

Resources