Search code examples
android-studiodartflutterjetbrains-idelive-templates

Android Studio Live Template for Flutter camelCase(String)?


Trying to setup a livetemplate for Flutter which is this:

S.of(context).$END$$lowerCaseName$ $lowerCaseName$":$SELECTION$

Where lowerCaseName is camelCase(String). But when I run it, I get an extra " right after $END$

For example, if I select "test string" in my code and surround with the live template, instead of getting this:

String test = S.of(context).TestString TestString":"test string";

I get this:

String test = S.of(context)."TestString "TestString":"test string";

Any ideas?


Solution

  • the problem is that $SELECTION$ value is the whole string you select, including quotes. So you have to strip them somehow. I'd suggest using groovyScript() - see https://www.jetbrains.com/help/idea/edit-template-variables-dialog.html, http://bartololeo.blogspot.com/2014/01/idea-12-how-to-write-live-template-with.html. For example, the following function specified as expression for $lowerCaseName$ should do the thing:

    camelCase(groovyScript("_1.replace('\"', '')", SELECTION))