acomodate for situations where instance has less than 6 communities

This commit is contained in:
krawieck 2020-10-06 12:07:12 +02:00
parent 4058ebc200
commit c4ed57d393
1 changed files with 11 additions and 2 deletions

View File

@ -8,7 +8,6 @@ import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:url_launcher/url_launcher.dart' as ul;
import '../hooks/stores.dart';
import '../util/extensions/api.dart';
import '../util/goto.dart';
import '../util/text_color.dart';
import '../widgets/badge.dart';
@ -353,7 +352,7 @@ class _AboutTab extends HookWidget {
),
),
if (commSnap.hasData)
...commSnap.data.getRange(0, 6).map((e) => ListTile(
...commSnap.data.getRangeOrShorter(0, 6).map((e) => ListTile(
onTap: () =>
goToCommunity.byId(context, e.instanceUrl, e.id),
title: Text(e.name),
@ -469,3 +468,13 @@ class _Divider extends StatelessWidget {
child: Divider(),
);
}
extension GetRangeOrShorter on List {
Iterable getRangeOrShorter(int start, int end) {
if (length < end) {
return getRange(start, length);
} else {
return getRange(start, end);
}
}
}