Skip to content

Instantly share code, notes, and snippets.

@shakir915
Last active October 17, 2023 09:52
Show Gist options
  • Save shakir915/ef7c2e864a8f22942826acafc7b683e7 to your computer and use it in GitHub Desktop.
Save shakir915/ef7c2e864a8f22942826acafc7b683e7 to your computer and use it in GitHub Desktop.
Flutter EdgeInset replace with EdgeInsetsDirectional
/****
Flutter EdgeInset replace with EdgeInsetsDirectional
run this kotlin script file
UNTICK : Interactive Mode
TICK: Use REPL
edit folder path in "dir" (check code)
run in Android studio scratch file
* */
import java.io.File
var dir = File("/Users/shakir/AndroidStudioProjects/Masjid_Flutter/lib")
fun replace(file: File) {
var isEdited = false
var text = file.readText()
text = text.replace("const EdgeInsets", " EdgeInsets")
while (text.indexOf("EdgeInsets.") >= 0) {
var start = text.indexOf("EdgeInsets.")
var end = 0
for (i in start until text.length) {
if (text[i].toString() == ")") {
end = i + 1
break
}
}
val oldString = text.substring(start, end)
var newString = oldString
newString = newString.replace("EdgeInsets.", "EdgeInsetsDirectional.")
newString = newString.replace("left", "start")
newString = newString.replace("right", "end")
text = text.replace(subString, oldString)
isEdited = true
}
if (isEdited)
file.writeText(text)
}
fun travers(dir: File) {
dir.listFiles().forEach {
if (it.isDirectory) {
travers(it)
} else {
replace(it)
}
}
}
travers(dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment