dss function
Inserts a CSS rule with the given declarations markup and
returns a generated unique name to use as className
.
If isDev is true
, prefix
will be added before the generated class name for the sake of debugging.
The examples show how you would use this function.
querySelector('someSelector')
..className = dss(
'color: red;'
'font-size: 100px;',
prefix: 'big-red-')
..text = "Hello";
final forIpad = '@media (min-width: 768px) and (max-width: 1024px)';
final box = dss('''
color: red;
$forIpad {
color: blue;
}
''');
void main() {
querySelector('someSelector')
..className = box
..text = 'I\'m normally red, but turn blue on an iPad.';
}
Implementation
String dss(String markup, {String prefix}) {
String name = generateUniqueName();
if (isDev && prefix != null) {
name = prefix + name;
}
parseAndInsert('.$name', markup);
return name;
}