From 95386635f353ea88e815a877f0972cc29960fd60 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Sun, 3 Jan 2021 20:25:05 +0000 Subject: [PATCH] Disable implicit casts --- analysis_options.yaml | 3 +++ lib/pages/communities_tab.dart | 2 +- lib/pages/home_tab.dart | 14 +++++++------- lib/stores/accounts_store.dart | 8 +++++--- lib/widgets/comment_section.dart | 6 +++--- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index bb18466..f870a26 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -57,3 +57,6 @@ linter: analyzer: exclude: - "**/*.g.dart" + strong-mode: + implicit-casts: false + # implicit-dynamic: false diff --git a/lib/pages/communities_tab.dart b/lib/pages/communities_tab.dart index b76d0fc..433676f 100644 --- a/lib/pages/communities_tab.dart +++ b/lib/pages/communities_tab.dart @@ -138,7 +138,7 @@ class CommunitiesTab extends HookWidget { ), body: ListView( children: [ - for (final i in Iterable.generate(amountOfDisplayInstances)) + for (var i = 0; i < amountOfDisplayInstances; i++) Column( children: [ ListTile( diff --git a/lib/pages/home_tab.dart b/lib/pages/home_tab.dart index 95c6970..3c8902d 100644 --- a/lib/pages/home_tab.dart +++ b/lib/pages/home_tab.dart @@ -33,15 +33,13 @@ class HomeTab extends HookWidget { final isc = useInfiniteScrollController(); final theme = Theme.of(context); final instancesIcons = useMemoFuture(() async { - final map = {}; final instances = accStore.instances.toList(growable: false); final sites = await Future.wait(instances .map((e) => LemmyApi(e).v1.getSite().catchError((e) => null))); - for (final i in Iterable.generate(sites.length)) { - map[instances[i]] = sites[i].site.icon; - } - return map; + return { + for (var i = 0; i < sites.length; i++) instances[i]: sites[i].site.icon + }; }); handleListChange() async { @@ -268,14 +266,16 @@ class InfiniteHomeList extends HookWidget { )); final posts = await Future.wait(futures); final newPosts = []; - for (final i - in Iterable.generate(posts.map((e) => e.length).reduce(max))) { + final longest = posts.map((e) => e.length).reduce(max); + + for (var i = 0; i < longest; i++) { for (final el in posts) { if (el.elementAt(i) != null) { newPosts.add(el[i]); } } } + return newPosts; } diff --git a/lib/stores/accounts_store.dart b/lib/stores/accounts_store.dart index 8bb830a..754b275 100644 --- a/lib/stores/accounts_store.dart +++ b/lib/stores/accounts_store.dart @@ -47,11 +47,13 @@ class AccountsStore extends ChangeNotifier { ); // set saved settings or create defaults - _tokens = nestedMapsCast((json) => Jwt(json['raw'])); + _tokens = nestedMapsCast((json) => Jwt(json['raw'] as String)); _defaultAccount = prefs.getString(SharedPrefKeys.defaultAccount); _defaultAccounts = HashMap.of(Map.castFrom( - jsonDecode(prefs.getString(SharedPrefKeys.defaultAccounts) ?? 'null') ?? - {})); + jsonDecode(prefs.getString(SharedPrefKeys.defaultAccounts) ?? 'null') + as Map ?? + {}, + )); notifyListeners(); } diff --git a/lib/widgets/comment_section.dart b/lib/widgets/comment_section.dart index 46b80f6..20e4e31 100644 --- a/lib/widgets/comment_section.dart +++ b/lib/widgets/comment_section.dart @@ -60,8 +60,8 @@ class CommentSection extends HookWidget { children: [ for (final e in sortPairs.entries) ListTile( - leading: Icon(e.value[0]), - title: Text(e.value[1]), + leading: Icon(e.value[0] as IconData), + title: Text(e.value[1] as String), trailing: sorting.value == e.key ? const Icon(Icons.check) : null, @@ -79,7 +79,7 @@ class CommentSection extends HookWidget { ), child: Row( children: [ - Text(sortPairs[sorting.value][1]), + Text(sortPairs[sorting.value][1] as String), const Icon(Icons.arrow_drop_down), ], ),