DART : I have a switch case of enums, which are buttons, but all cases are executing only once. It wont work the second time i click the same button - flutter

Below is the switch case code, the main problem I have is, the code is fine for the first time that is appropriate output is rendered, but when I click the button (enum for example Scholarships) the code wont execute
PopupMenuButton(
onSelected: (Category selectedOffer) {
switch (selectedOffer) {
case Category.Scholarships:
{
offersData.showScholarshipsOnly();
}
break;
case Category.Investing:
{
offersData.showInvestingOnly();
}
break;
case Category.Courses:
{
offersData.showCoursesOnly();
}
break;
case Category.Discounts:
{
offersData.showDiscountsOnly();
}
break;
case Category.Finance:
{
offersData.showFinanceOnly();
}
break;
case Category.All:
{
offersData.showAll();
} break;
}
These are the functions which are linked to the above conditions
List<Offers> get offerList {
if (_showScholarships) {
return _offerList.where((selOffer) =>
selOffer.category.name.contains('Scholarships')).toList();
}
else if (_showCourses) {
return _offerList.where((selOffer) =>
selOffer.category.name.contains('Courses')).toList();
}
else if (_showInvesting) {
return _offerList.where((selOffer) =>
selOffer.category.name.contains('Investing')).toList();
}
else if (_showFinance) {
return _offerList.where((selOffer) =>
selOffer.category.name.contains('Finance')).toList();
}
else if (_showDiscounts) {
return _offerList.where((selOffer) =>
selOffer.category.name.contains('Discounts')).toList();
}
else if (_showAll) {
return _offerList.where((selOffer) =>
selOffer.category.name.contains(
'Investing,Finance,Discounts,Insurance,Courses,Scholarships'))
.toList();
}
return _offerList;
}

Related

Unhandled Exception: Unhandled error 'package:bloc/src/transition.dart': Failed assertion: line 27 pos 16: 'nextState != null': is not true

I am getting this error while updating a value in state . please suggest me how to resolve it. what is best way to update current state while working with BLOC in flutter. My BLOC class code added. This Error Occurs onItemClick Event.
onItemClicked: (e) async* {
try {
yield walmartState;
List<CommonDataObj> dataList =
walmartItemChanged(e.index, e.walmartList);
yield state.copyWith(walmartList: some(right(dataList)));
LinkedHashMap<String, RequestData> reqMap = state.requestDataMap;
dataList.forEach((element) {
if (element.isSelected) {
RequestData data = RequestData(element.intStoreId, element.intId);
if (reqMap.containsKey(e.key)) {
reqMap.update(e.key, (value) => data);
} else {
reqMap.putIfAbsent(e.key, () => data);
}
} else {
if (reqMap.containsKey(e.key)) {
var value = reqMap[e.key];
if (value.int_product_id == element.intId &&
value.int_store_id == element.intStoreId) {
reqMap.remove(e.key);
}
}
}
});
yield state.copyWith(requestDataMap: reqMap);
yield state.copyWith(requestDataMap: reqMap);
print('State request Data Map : $reqMap');
} catch (e) {
print(e);
}
try {
bool selected = false;
e.currentDataMap.forEach((key, value) {
for (var item in value) {
if (item.isSelected) {
selected = true;
break;
}
}
});
int curQuantity = state.currentQuantity;
if (curQuantity == 0) {
curQuantity = curQuantity + 1;
} else if (curQuantity > 0 && !selected) {
curQuantity = 0;
}
var newState = state.copyWith(currentQuantity: curQuantity);
yield newState;
} catch (e) {
print(e);
}
}

How can i fix my code to make my count value update from my function

How can i make _handlerRadioValuegender() update my count value which I declared as var count = 3 on top.
I tried what i can do and here are all debugprint() functions results. It is now always taking the value which I define on top means my _handler function has no effect on the count value.
var count = 3;
int _handleRadioValuegender(int value) {
setState(() {
_gender = value;
switch (_gender) {
case 0:
debugPrint('case0');
count++;
debugPrint('$count');
break;
case 1:
debugPrint('case1');
this.count++;
this.count++;
debugPrint('$count');
break;
}
});
}
String gender() {
if (count == 1) {
debugPrint('$count');
return 'Male';
} else if (count == 3) {
debugPrint('$count');
return 'Female';
} else {
debugPrint('$count');
}
}
I want my count value to be updated from my _handlerRadioValuegender() function and when gender() access it, then it should return value according to that.Screenshot of debugprints()

Cancel Or Exit from PromptDialog.Choice Flow in Microsoft Bot Framework

i have a Prompt with 4 options, the last option is user can quit the Prompt,
i want to implement some code so that the bot exit the Prompt
Image
PromptDialog.Choice(context, this.OnOptionSelected, new List<string>() { FlightsOption, HotelsOption, TrainOption, GobackOption }, "Sure..! Tell me what booking would like to make..?", "Not a valid option", 3);
in above image i had implemented quit option on which if user selects quit it goes to Switch case of quit.
i had also tried context.quit but it throws error
private async Task OnOptionSelected(IDialogContext context, IAwaitable<string> result)
{
try
{
string optionSelected = await result;
switch (optionSelected)
{
case FlightsOption:
context.Call(new FlightDialog(), this.ResumeAfterOptionDialog);
break;
case HotelsOption:
context.Call(new HotelsDialog(), this.ResumeAfterOptionDialog);
break;
case TrainOption:
context.Call(new TrainDialog(), this.ResumeAfterOptionDialog);
break;
case GobackOption:
//want some code here to quit the form
break;
}
}
First of all this is not a Form Flow. This is prompt.
Now You can do something like, either you exit the dialog from the stack like this
try
{
string optionSelected = await result;
switch (optionSelected)
{
case FlightsOption:
context.Call(new FlightDialog(), this.ResumeAfterOptionDialog);
break;
case HotelsOption:
context.Call(new HotelsDialog(), this.ResumeAfterOptionDialog);
break;
case TrainOption:
context.Call(new TrainDialog(), this.ResumeAfterOptionDialog);
break;
case GobackOption:
context.Done<object>(null);
break;
}
}
Or,
You can tell something and then wait for other message in the same dialog like this
try
{
string optionSelected = await result;
switch (optionSelected)
{
case FlightsOption:
context.Call(new FlightDialog(), this.ResumeAfterOptionDialog);
break;
case HotelsOption:
context.Call(new HotelsDialog(), this.ResumeAfterOptionDialog);
break;
case TrainOption:
context.Call(new TrainDialog(), this.ResumeAfterOptionDialog);
break;
case GobackOption:
await context.PostAsync("Ok, you came back. Now tell something new.");
context.Wait(MessageReceivedAsync);
break;
}
}
And the next message will go here
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
context.Wait(MessageReceivedAsync);
}

Collection find method doesn't work on Angular 2 recursive function

I'm developing Angular2 with Meteor.
When I make a little component with a recursive function, it has some weird error.
Here is my part of codes.
Not recursive - return a result
ngOnInit() {
//this.current_canvas return the right results
this.current_canvas = this.get_canvase(1);
}
get_canvase(which_canvas): Canvas[] {
if (!isNaN(which_canvas)) {
this.current_canvas_id = which_canvas;
return CanvasContents.find().map((messages: Canvas[]) => { return messages; })[0].content;
return '';
} else if(which_canvas == 'most-recent') {
this.get_canvase(1);
}
}
Recursive - Don't return a result
ngOnInit() {
//this.current_canvas Goes to NUll
this.current_canvas = this.get_canvase('most-recent');
}
get_canvase(which_canvas): Canvas[] {
if (!isNaN(which_canvas)) {
this.current_canvas_id = which_canvas;
console.log('this.current_canvas_id : ' + this.current_canvas_id);
return CanvasContents.find().map((messages: Canvas[]) => { return messages; })[0].content;
return '';
} else if(which_canvas == 'most-recent') {
this.get_canvase(1);
}
}
Have I used a wrong syntax? or is it on wrong Angular2 state to get right result?

Any other option to deploy in jboss server ither than hot deployment?

I want to know what are the methods to deploy in jboss server other than hot deployment.
Get the client and the builder to build plans:
ModelControllerClient client = ModelControllerClient.Factory.create(host, port);
ServerDeploymentManager manager = ServerDeploymentManager.Factory.create(client);
DeploymentPlanBuilder builder = manager.newDeploymentPlan();
And the method to execute any kind of operation (here some ones are implemented):
public DeployementActionStatus execute(Type deploy) throws IOException
{
List<Throwable> errors = new LinkedList<Throwable>();
DeployementActionStatus status = DeployementActionStatus.SUCCESS;
switch (deploy)
{
case DEPLOY:
if (archive != null)
{
plan = builder.add(archive).deploy(archive.getName()).build();
}
else
{
return DeployementActionStatus.FAILURE;
}
break;
case REDEPLOY:
{
if (archive != null)
{
plan = builder.redeploy(archive.getName()).build();
}
else
{
return DeployementActionStatus.FAILURE;
}
break;
}
case UNDEPLOY:
{
plan = builder.undeploy(getApplicationName()).build();
break;
}
case REMOVE:
{
plan = builder.remove(getApplicationName()).build();
break;
}
default:
plan = null;
break;
}
if (plan == null)
{
throw new IllegalStateException("Invalid type: " + deploy);
}
if (plan.getDeploymentActions().size() > 0)
{
try
{
final ServerDeploymentPlanResult planResult = manager.execute(plan).get();
// Check the results
for (DeploymentAction action : plan.getDeploymentActions())
{
final ServerDeploymentActionResult actionResult = planResult.getDeploymentActionResult(action
.getId());
final ServerUpdateActionResult.Result result = actionResult.getResult();
switch (result)
{
case FAILED:
case NOT_EXECUTED:
case ROLLED_BACK:
{
log.error(actionResult.getDeploymentException());
if (actionResult.getDeploymentException().getMessage() != null
&& actionResult.getDeploymentException().getMessage().contains("Duplicate"))
{
status = DeployementActionStatus.FAILURE_ALREADY_DEPLOYED;
}
else
{
status = DeployementActionStatus.FAILURE;
}
break;
}
case CONFIGURATION_MODIFIED_REQUIRES_RESTART:
// Should show warning
break;
default:
break;
}
}
}
catch (InterruptedException e)
{
errors.add(e);
status = DeployementActionStatus.FAILURE;
}
catch (ExecutionException e)
{
errors.add(e);
status = DeployementActionStatus.FAILURE;
}
catch (Exception e)
{
if (e instanceof RuntimeException)
{
status = DeployementActionStatus.CONNECTION_TO_SERVER_FAILED;
}
}
}
return status;
}
Deploying is considered hot only when JBoss is running. If you don't want hot deployment you can turn off deployment scanner [1] or stop JBoss and deploy the artifact.
[1] https://community.jboss.org/wiki/ConfiguringTheDeploymentScannerInConfjbossSystemxml