forked from firka/firka
feat: shorten teacher's name
This commit is contained in:
@@ -294,4 +294,26 @@ extension StringExtension on String {
|
||||
if (length == 1) this[0].toUpperCase();
|
||||
return this[0].toUpperCase() + substring(1, length);
|
||||
}
|
||||
|
||||
String shortenName([int start = 0]) {
|
||||
if (length <= 16 || start >= length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
int index = indexOf(" ", start);
|
||||
if (index == -1) {
|
||||
return this;
|
||||
}
|
||||
|
||||
String string = substring(start, index);
|
||||
if (string.endsWith(".")) {
|
||||
return this;
|
||||
}
|
||||
|
||||
return replaceRange(
|
||||
start,
|
||||
index,
|
||||
"${string[0]}.",
|
||||
).shortenName(index - string.length + 2 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ class LessonWidget extends StatelessWidget {
|
||||
),
|
||||
showSubstitutions
|
||||
? Text(
|
||||
lesson.substituteTeacher!,
|
||||
lesson.substituteTeacher!.shortenName(),
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
|
||||
@@ -204,7 +204,7 @@ class LessonBigWidget extends StatelessWidget {
|
||||
),
|
||||
if (isSubstituted)
|
||||
Text(
|
||||
lesson.substituteTeacher!,
|
||||
lesson.substituteTeacher!.shortenName(),
|
||||
style: appStyle.fonts.B_14R.apply(
|
||||
color: appStyle.colors.textSecondary,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user