I m trying to fetch order details from website and getting error "A non-null String must be provided to a Text widget' - flutter

1.getting error on this line as null
enter code here
return OrderItem(
order: model.myOrders[index],
onRefresh: refreshMyOrders,
);
}),
),
)

You have to check if the indexed order is null and set a default value to protect your code from these types of errors like this:
return OrderItem(
order: model.myOrders[index] ?? 'Default Value',
onRefresh: refreshMyOrders,
);
}),
),
)

Related

flutter- I don't know the difference between these two case

Case 1 :
children: DUMMY_CATEGORIES.map((catData) {
CategoryItem(
catData.title,
catData.color,
);
}).toList(),
Case 2 :
children: DUMMY_CATEGORIES
.map(
(catData) => CategoryItem(
catData.title,
catData.color,
),
)
.toList(),
Case 1 causes an error.
Isn't the two cases the same syntax?
Why is this error occurring?
════════ Exception caught by rendering library ═════════════════════════════
Null check operator used on a null value
The relevant error-causing widget was
GridView
lib\categories_screen.dart:12
═════════════════════════════════════════════════════════════
Case 2 uses the Fat Arrow Expression or Lambda Function Expression, a syntax to write a function on a single line using => syntax AKA fat arrow. more info
DUMMY_CATEGORIES.map(
(catData) => CategoryItem(
catData.title,
catData.color,
),
).toList(),
Fat Arrow Syntax:
(args) => expression
If expression has a return type (in your case, a CategoryItem), it directly returns.
It is the same as your Case 1 with a return statement:
DUMMY_CATEGORIES.map(
(catData) {
return CategoryItem(
catData.title,
catData.color,
),
}
).toList(),

How to get last inserted record in Meteor mongo?

I want to get last inserted item in minimongo. currently i'm doing it in this way (code on client side):
addBook()
{
BookCollection.insert(
this.book , ( err , insertedBook_id )=>
{
this.book_saved = true;
console.group('Output:')
console.log(err);
console.log( insertedBook_id );
console.log(
BookCollection.find({_id: insertedBook_id})
.fetch()
);
console.groupEnd();
//this.router.navigate(['/book', insertedBook_id]);
}
);
}
Output in console:
undefined
t6Lwrv4od854tE7st
[]
As you can see, when i redirect to newly created page, i cant find a book, but in mongo shell i clearly see that record was added. Should i wait for some event like BookCollection.insert(this.book).then( . . . )? Please help me!)
When i go back to the 'all books page', i see new record and can click, all works normal, no errors.
In the /book controller:
ngOnInit()
{
this.sub = this.curr_route.params.subscribe(
params=>
{
this.book = BookCollection.findOne( params[ '_id' ] ); // .fetch() == []
//if(!this.book)
// this.router.navigate(['/books']);
Meteor.subscribe(
'book' , params[ '_id' ] , ()=>
{
this.book = BookCollection.findOne( params[ '_id' ] );
} , true
)
console.groupCollapsed( 'BookDetailsCardComponent log data:' )
console.group( 'Book:' );
console.log( this.book );
console.groupEnd();
console.groupEnd();
} , true
);
}
This is probably a timing issue. The _id is most likely created and returned immediately while the actual data is inserted into the database, which would explain why doing a find() on that _id right away comes back as an empty array.
Is there a reason you are doing your insert from the client rather than doing it on the server and using a Meteor method to initiate it? Changing to this approach might resolve your issue.

Protractor not scrolling to test element

Trying to write some protractor tests for ionic, realized the selector element( by.css('.selector')); no longer scrolls to the element. Which when it's not visible in the browser, automatically fails the test.
Took me awhile to figure it out. Using a ptor.sleep(2000) to delay the page after browser.get('domain'); and then If I scroll through the sections where the elements are being tested, they pass (as expected).
I believe this has something to do with ionic taking over scroll events.
Has anyone ran into this before or have some sort of scrollTo implementation for all elements?
sample test
"use strict";
/* Tests */
var ptor = protractor.getInstance();
describe( "Register page", function ()
{
browser.get( "#/register" );
ptor.sleep(2000);
it( "Check SMS Preference", function ()
{
var smsLabelConfirm = element( by.css( ".sms-confirm" ) ),
smsLabelDeny = element( by.css( ".sms-deny" ) ),
smsInputConfirm = element ( by.id( "sms-confirm" ) ),
smsInputDeny = element ( by.id( "sms-deny" ) );
smsLabelConfirm.click();
expect( smsInputConfirm.getAttribute( "checked" ) ).toBe( "true" );
expect( smsInputDeny.getAttribute( "checked" ) ).toBe( null );
smsLabelDeny.click();
expect( smsInputConfirm.getAttribute( "checked" ) ).toBe( null );
expect( smsInputDeny.getAttribute( "checked" ) ).toBe( "true" );
} );
});
Ended up using a variation of the answer provided here: How to set focus on a section of my web page then scroll down
Changed it so the function just takes the element as an argument for reusability. Seems to be working.
var ptor = protractor.getInstance();
var scrollIntoView = function (element) {
arguments[0].scrollIntoView();
};
describe( "Register page", function ()
{
browser.get( "#/register" );
ptor.sleep(2000);
it( "Check SMS Preference", function ()
{
var smsLabelConfirm = element( by.css( ".sms-confirm" ) ),
smsLabelDeny = element( by.css( ".sms-deny" ) ),
smsInputConfirm = element ( by.id( "sms-confirm" ) ),
smsInputDeny = element ( by.id( "sms-deny" ) );
browser.executeScript(scrollIntoView, smsLabelConfirm);
smsLabelConfirm.click();
expect( smsInputConfirm.getAttribute( "checked" ) ).toBe( "true" );
expect( smsInputDeny.getAttribute( "checked" ) ).toBe( null );
smsLabelDeny.click();
expect( smsInputConfirm.getAttribute( "checked" ) ).toBe( null );
expect( smsInputDeny.getAttribute( "checked" ) ).toBe( "true" );
} );
});

CKEditor Link dialog modification

I am trying to add a drop down to CKEditor's link dialog. When selected, the drop down should insert corresponding class name to the link.
CKEDITOR.on( 'dialogDefinition', function( ev ) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if ( dialogName == 'link' ) {
var infoTab = dialogDefinition.getContents( 'info' );
infoTab.add({
type: 'select',
label: 'Display link as a button',
id: 'buttonType',
'default': '',
items: [
['- Not button -', ''],
['Button one', 'btn-primary'],
['Button two', 'btn-success'],
['Button three', 'btn-danger']
],
commit: function(data) {
data.className = this.getValue();
}
});
}
});
I have a feeling commit function is not doing the job, but cannot figure out how to make it work. I saw a code that almost does the same thing as I want at http://www.lxg.de/code/simplify-ckeditors-link-dialog. I tried it and it does not work either.
I am using CKEditor 4.3.2.
I appreciate your help in advance.
If you console.log the data object in link dialog's onOk, you'll find quite a different hierarchy. Element classes are in data.advanced.advCSSClasses. But even if you decide to override (or extend) the value of this property in your commit, your string will be nuked by the original commit of advCSSClasses input field ("Advanced" tab) anyway. So the approach got to be a little bit different:
Always store the value of the select in data.
Override commit of advCSSClasses input field to consider stored value.
Remember to execute the original commit of advCSSClasses input.
Here we go:
CKEDITOR.on( 'dialogDefinition', function( ev ) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if ( dialogName == 'link' ) {
var infoTab = dialogDefinition.getContents( 'info' ),
advTab = dialogDefinition.getContents( 'advanced' ),
advCSSClasses = advTab.get( 'advCSSClasses' );
infoTab.add( {
type: 'select',
label: 'Display link as a button',
id: 'buttonType',
'default': '',
items: [
['- Not button -', ''],
['Button one', 'btn-primary'],
['Button two', 'btn-success'],
['Button three', 'btn-danger']
],
commit: function( data ) {
data.buttonType = this.getValue();
}
});
var orgAdvCSSClassesCommit = advCSSClasses.commit;
advCSSClasses.commit = function( data ) {
orgAdvCSSClassesCommit.apply( this, arguments );
if ( data.buttonType && data.advanced.advCSSClasses.indexOf( data.buttonType ) == -1 )
data.advanced.advCSSClasses += ' ' + data.buttonType;
};
}
});
Now you got to only write a setup function which will detect whether one of your button classes is present to set a proper value of your select field once the dialog is open.

I can't get htmlpurifier to allow anchors (a tag with name attribute)

I really can't get htmlpurifier to allow name attributes on a tags. I want to allow tinyMCE to function with anchors. I suppose the name attribute is deprecated an id should be used, but tinyMCE produces name attributes. Is there somehow I can either transform them into id="" or accept them?
Following the docs I try this but it doesn't work
require_once( 'HTMLPurifier.standalone.php' );
$config = HTMLPurifier_Config::createDefault();
$config->set( 'HTML.Doctype' , 'XHTML 1.0 Transitional' );
$config->set( 'Cache.DefinitionImpl', null ); // remove this later!
$config->set( 'Core.CollectErrors' , true );
$def = $config->getHTMLDefinition( true );
$def->addAttribute( 'a', 'name' , 'ID' );
// $def->addAttribute( 'a', 'name' , 'CDATA' ); // does not work either
// $def->addAttribute( 'a', 'name' , 'Text' ); // does not work either
$purifier = new HTMLPurifier( $config );
$purifier->purify( '<a name="test"></a>' );
echo $purifier->context->get( 'ErrorCollector' )->getHTMLFormatted( $config );
// output:
// Error Line 1, Column 0: name attribute on <a> removed
http://htmlpurifier.org/docs/enduser-id.html
(Oh, and remove the custom HTML definition and declarations.)