Enable new lints

This commit is contained in:
shilangyu 2022-05-11 22:23:18 +02:00
parent 3f33cac3ed
commit 4533be634e
32 changed files with 74 additions and 90 deletions

View File

@ -112,12 +112,15 @@ linter:
- unnecessary_string_interpolations - unnecessary_string_interpolations
- unnecessary_this - unnecessary_this
- unrelated_type_equality_checks - unrelated_type_equality_checks
- use_colored_box
- use_enums
- use_full_hex_values_for_flutter_colors - use_full_hex_values_for_flutter_colors
- use_is_even_rather_than_modulo - use_is_even_rather_than_modulo
- use_named_constants - use_named_constants
- use_raw_strings - use_raw_strings
- use_rethrow_when_possible - use_rethrow_when_possible
- use_setters_to_change_properties - use_setters_to_change_properties
- use_super_parameters
- use_test_throws_matchers - use_test_throws_matchers
- use_to_and_as_if_applicable - use_to_and_as_if_applicable
- void_checks - void_checks

View File

@ -7,10 +7,8 @@ enum CommentSortType {
top, top,
new_, new_,
old, old,
chat, chat;
}
extension on CommentSortType {
/// returns a compare function for sorting a CommentTree according /// returns a compare function for sorting a CommentTree according
/// to the comment sort type /// to the comment sort type
int Function(CommentTree a, CommentTree b) get sortFunction { int Function(CommentTree a, CommentTree b) get sortFunction {

View File

@ -11,8 +11,11 @@ class CommunitiesListPage extends StatelessWidget {
final String title; final String title;
final FetcherWithSorting<CommunityView> fetcher; final FetcherWithSorting<CommunityView> fetcher;
const CommunitiesListPage({Key? key, required this.fetcher, this.title = ''}) const CommunitiesListPage({
: super(key: key); super.key,
required this.fetcher,
this.title = '',
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -42,8 +45,7 @@ class CommunitiesListPage extends StatelessWidget {
class CommunitiesListItem extends StatelessWidget { class CommunitiesListItem extends StatelessWidget {
final CommunityView community; final CommunityView community;
const CommunitiesListItem({Key? key, required this.community}) const CommunitiesListItem({super.key, required this.community});
: super(key: key);
@override @override
Widget build(BuildContext context) => ListTile( Widget build(BuildContext context) => ListTile(

View File

@ -241,9 +241,11 @@ class _CommunitySubscribeToggle extends HookWidget {
final int communityId; final int communityId;
final String instanceHost; final String instanceHost;
const _CommunitySubscribeToggle( const _CommunitySubscribeToggle({
{required this.instanceHost, required this.communityId, Key? key}) required this.instanceHost,
: super(key: key); required this.communityId,
super.key,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -15,8 +15,7 @@ import 'community_store.dart';
class CommmunityAboutTab extends StatelessWidget { class CommmunityAboutTab extends StatelessWidget {
final FullCommunityView fullCommunityView; final FullCommunityView fullCommunityView;
const CommmunityAboutTab(this.fullCommunityView, {Key? key}) const CommmunityAboutTab(this.fullCommunityView, {super.key});
: super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -14,8 +14,7 @@ import 'community_store.dart';
class CommunityMoreMenu extends HookWidget { class CommunityMoreMenu extends HookWidget {
final FullCommunityView fullCommunityView; final FullCommunityView fullCommunityView;
const CommunityMoreMenu({Key? key, required this.fullCommunityView}) const CommunityMoreMenu({super.key, required this.fullCommunityView});
: super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -13,7 +13,7 @@ import '../../widgets/avatar.dart';
import 'create_post_store.dart'; import 'create_post_store.dart';
class CreatePostCommunityPicker extends HookWidget { class CreatePostCommunityPicker extends HookWidget {
const CreatePostCommunityPicker({Key? key}) : super(key: key); const CreatePostCommunityPicker({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -6,7 +6,7 @@ import '../../widgets/radio_picker.dart';
import 'create_post_store.dart'; import 'create_post_store.dart';
class CreatePostInstancePicker extends StatelessWidget { class CreatePostInstancePicker extends StatelessWidget {
const CreatePostInstancePicker({Key? key}) : super(key: key); const CreatePostInstancePicker({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -27,7 +27,7 @@ class CommentSection extends StatelessWidget {
CommentSortType.chat: _SortSelection(Icons.chat, L10nStrings.chat), CommentSortType.chat: _SortSelection(Icons.chat, L10nStrings.chat),
}; };
const CommentSection({Key? key}) : super(key: key); const CommentSection({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -11,7 +11,7 @@ import '../../widgets/info_table_popup.dart';
class InstanceMoreMenu extends StatelessWidget { class InstanceMoreMenu extends StatelessWidget {
final FullSiteView site; final FullSiteView site;
const InstanceMoreMenu({Key? key, required this.site}) : super(key: key); const InstanceMoreMenu({super.key, required this.site});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -86,7 +86,7 @@ class ManageAccountPage extends HookWidget {
} }
class _ManageAccount extends HookWidget { class _ManageAccount extends HookWidget {
const _ManageAccount({Key? key, required this.user}) : super(key: key); const _ManageAccount({required this.user});
final LocalUserSettingsView user; final LocalUserSettingsView user;
@ -396,13 +396,12 @@ class _ImagePicker extends HookWidget {
final ObjectRef<VoidCallback?> informAcceptedRef; final ObjectRef<VoidCallback?> informAcceptedRef;
const _ImagePicker({ const _ImagePicker({
Key? key,
required this.initialUrl, required this.initialUrl,
required this.name, required this.name,
required this.user, required this.user,
required this.onChange, required this.onChange,
required this.informAcceptedRef, required this.informAcceptedRef,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -8,7 +8,7 @@ import '../../widgets/avatar.dart';
import 'modlog_entry.dart'; import 'modlog_entry.dart';
class ModlogTable extends StatelessWidget { class ModlogTable extends StatelessWidget {
const ModlogTable({Key? key, required this.modlog}) : super(key: key); const ModlogTable({super.key, required this.modlog});
final Modlog modlog; final Modlog modlog;

View File

@ -10,7 +10,7 @@ import 'community_block_store.dart';
import 'user_block_store.dart'; import 'user_block_store.dart';
class BlockPersonTile extends StatelessWidget { class BlockPersonTile extends StatelessWidget {
const BlockPersonTile({Key? key}) : super(key: key); const BlockPersonTile({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -40,7 +40,7 @@ class BlockPersonTile extends StatelessWidget {
} }
class BlockCommunityTile extends HookWidget { class BlockCommunityTile extends HookWidget {
const BlockCommunityTile({Key? key}) : super(key: key); const BlockCommunityTile({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -185,10 +185,9 @@ class _AccountOptions extends HookWidget {
final String username; final String username;
const _AccountOptions({ const _AccountOptions({
Key? key,
required this.instanceHost, required this.instanceHost,
required this.username, required this.username,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -12,8 +12,7 @@ class UsersListPage extends StatelessWidget {
final String title; final String title;
final Fetcher<PersonViewSafe> fetcher; final Fetcher<PersonViewSafe> fetcher;
const UsersListPage({Key? key, required this.fetcher, this.title = ''}) const UsersListPage({super.key, required this.fetcher, this.title = ''});
: super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -41,7 +40,7 @@ class UsersListPage extends StatelessWidget {
class UsersListItem extends StatelessWidget { class UsersListItem extends StatelessWidget {
final PersonViewSafe user; final PersonViewSafe user;
const UsersListItem({Key? key, required this.user}) : super(key: key); const UsersListItem({super.key, required this.user});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -18,12 +18,12 @@ class AsyncStoreListener<T> extends SingleChildStatelessWidget {
)? onSuccess; )? onSuccess;
const AsyncStoreListener({ const AsyncStoreListener({
Key? key, super.key,
required this.asyncStore, required this.asyncStore,
this.successMessageBuilder, this.successMessageBuilder,
this.onSuccess, this.onSuccess,
Widget? child, super.child,
}) : super(key: key, child: child); });
@override @override
Widget buildWithChild(BuildContext context, Widget? child) { Widget buildWithChild(BuildContext context, Widget? child) {

View File

@ -59,7 +59,6 @@ void goToMedia(BuildContext context, String url) => Navigator.push(
context, context,
PageRouteBuilder( PageRouteBuilder(
pageBuilder: (_, __, ___) => MediaViewPage(url), pageBuilder: (_, __, ___) => MediaViewPage(url),
transitionDuration: const Duration(milliseconds: 300),
opaque: false, opaque: false,
transitionsBuilder: (_, animation, __, child) => transitionsBuilder: (_, animation, __, child) =>
FadeTransition(opacity: animation, child: child), FadeTransition(opacity: animation, child: child),

View File

@ -8,34 +8,24 @@ import 'observer_consumers.dart';
/// Important: this will not make [context.watch] react to changes /// Important: this will not make [context.watch] react to changes
class MobxProvider<T extends Store> extends Provider<T> { class MobxProvider<T extends Store> extends Provider<T> {
MobxProvider({ MobxProvider({
Key? key, super.key,
required Create<T> create, required super.create,
bool? lazy, super.lazy,
TransitionBuilder? builder, super.builder,
Widget? child, super.child,
}) : super( }) : super(
key: key,
create: create,
dispose: (context, store) { dispose: (context, store) {
if (store is DisposableStore) store.dispose(); if (store is DisposableStore) store.dispose();
}, },
lazy: lazy,
builder: builder,
child: child,
); );
/// will not dispose the store /// will not dispose the store
MobxProvider.value({ MobxProvider.value({
Key? key, super.key,
required T value, required super.value,
TransitionBuilder? builder, super.builder,
Widget? child, super.child,
}) : super.value( }) : super.value();
key: key,
builder: builder,
value: value,
child: child,
);
} }
/// tracks reactions and disposes them in [DisposableStore.dispose] /// tracks reactions and disposes them in [DisposableStore.dispose]

View File

@ -14,10 +14,10 @@ class ObserverBuilder<T extends Store> extends StatelessWidget {
final MobxBuilder<T> builder; final MobxBuilder<T> builder;
const ObserverBuilder({ const ObserverBuilder({
Key? key, super.key,
this.store, this.store,
required this.builder, required this.builder,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -38,11 +38,11 @@ class ObserverListener<T extends Store> extends HookWidget {
final Widget child; final Widget child;
const ObserverListener({ const ObserverListener({
Key? key, super.key,
this.store, this.store,
required this.listener, required this.listener,
required this.child, required this.child,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -64,11 +64,11 @@ class ObserverConsumer<T extends Store> extends HookWidget {
final MobxBuilder<T> builder; final MobxBuilder<T> builder;
const ObserverConsumer({ const ObserverConsumer({
Key? key, super.key,
this.store, this.store,
required this.listener, required this.listener,
required this.builder, required this.builder,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -96,7 +96,7 @@ class AboutTile extends HookWidget {
class ChangelogPage extends StatelessWidget { class ChangelogPage extends StatelessWidget {
final String changelog; final String changelog;
const ChangelogPage(this.changelog, {Key? key}) : super(key: key); const ChangelogPage(this.changelog, {super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -10,14 +10,14 @@ import 'cached_network_image.dart';
/// Can be disabled with `noBlank` /// Can be disabled with `noBlank`
class Avatar extends HookWidget { class Avatar extends HookWidget {
const Avatar({ const Avatar({
Key? key, super.key,
required this.url, required this.url,
this.radius = 25, this.radius = 25,
this.noBlank = false, this.noBlank = false,
this.alwaysShow = false, this.alwaysShow = false,
this.padding = EdgeInsets.zero, this.padding = EdgeInsets.zero,
this.onTap, this.onTap,
}) : super(key: key); });
final String? url; final String? url;
final double radius; final double radius;

View File

@ -41,8 +41,8 @@ class CachedNetworkImage extends StatelessWidget {
this.width, this.width,
this.fit, this.fit,
this.cache = true, this.cache = true,
Key? key, super.key,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -35,8 +35,8 @@ class CommentWidget extends StatelessWidget {
this.canBeMarkedAsRead = false, this.canBeMarkedAsRead = false,
this.hideOnRead = false, this.hideOnRead = false,
this.userMentionId, this.userMentionId,
Key? key, super.key,
}) : super(key: key); });
CommentWidget.fromCommentView( CommentWidget.fromCommentView(
CommentView cv, { CommentView cv, {

View File

@ -13,7 +13,7 @@ import 'comment_more_menu_button.dart';
import 'comment_store.dart'; import 'comment_store.dart';
class CommentActions extends HookWidget { class CommentActions extends HookWidget {
const CommentActions({Key? key}) : super(key: key); const CommentActions({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -18,7 +18,7 @@ import 'comment.dart';
import 'comment_store.dart'; import 'comment_store.dart';
class CommentMoreMenuButton extends HookWidget { class CommentMoreMenuButton extends HookWidget {
const CommentMoreMenuButton({Key? key}) : super(key: key); const CommentMoreMenuButton({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -44,9 +44,8 @@ class _CommentMoreMenuPopup extends HookWidget {
final CommentStore store; final CommentStore store;
const _CommentMoreMenuPopup({ const _CommentMoreMenuPopup({
Key? key,
required this.store, required this.store,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -20,7 +20,7 @@ class Editor extends HookWidget {
final String instanceHost; final String instanceHost;
const Editor({ const Editor({
Key? key, super.key,
this.controller, this.controller,
this.focusNode, this.focusNode,
this.onSubmitted, this.onSubmitted,
@ -32,7 +32,7 @@ class Editor extends HookWidget {
this.fancy = false, this.fancy = false,
required this.instanceHost, required this.instanceHost,
this.autofocus = false, this.autofocus = false,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -9,10 +9,10 @@ class FullscreenableImage extends StatelessWidget {
final Widget child; final Widget child;
const FullscreenableImage({ const FullscreenableImage({
Key? key, super.key,
required this.url, required this.url,
required this.child, required this.child,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) => InkWell( Widget build(BuildContext context) => InkWell(

View File

@ -6,10 +6,10 @@ class PullToRefresh extends StatelessWidget {
final Widget child; final Widget child;
const PullToRefresh({ const PullToRefresh({
Key? key, super.key,
required this.onRefresh, required this.onRefresh,
required this.child, required this.child,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -20,7 +20,7 @@ class RadioPicker<T> extends StatelessWidget {
final Widget? trailing; final Widget? trailing;
const RadioPicker({ const RadioPicker({
Key? key, super.key,
required this.values, required this.values,
required this.groupValue, required this.groupValue,
required this.onChanged, required this.onChanged,
@ -28,7 +28,7 @@ class RadioPicker<T> extends StatelessWidget {
this.buttonBuilder, this.buttonBuilder,
this.title, this.title,
this.trailing, this.trailing,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -70,8 +70,8 @@ class SortableInfiniteList<T> extends HookWidget {
class InfinitePostList extends SortableInfiniteList<PostView> { class InfinitePostList extends SortableInfiniteList<PostView> {
InfinitePostList({ InfinitePostList({
required FetcherWithSorting<PostView> fetcher, required super.fetcher,
InfiniteScrollController? controller, super.controller,
}) : super( }) : super(
itemBuilder: (post) => Column( itemBuilder: (post) => Column(
children: [ children: [
@ -79,8 +79,6 @@ class InfinitePostList extends SortableInfiniteList<PostView> {
const SizedBox(height: 20), const SizedBox(height: 20),
], ],
), ),
fetcher: fetcher,
controller: controller,
noItems: const Text('there are no posts'), noItems: const Text('there are no posts'),
uniqueProp: (item) => item.post.apId, uniqueProp: (item) => item.post.apId,
); );
@ -88,15 +86,13 @@ class InfinitePostList extends SortableInfiniteList<PostView> {
class InfiniteCommentList extends SortableInfiniteList<CommentView> { class InfiniteCommentList extends SortableInfiniteList<CommentView> {
InfiniteCommentList({ InfiniteCommentList({
required FetcherWithSorting<CommentView> fetcher, required super.fetcher,
InfiniteScrollController? controller, super.controller,
}) : super( }) : super(
itemBuilder: (comment) => CommentWidget( itemBuilder: (comment) => CommentWidget(
CommentTree(comment), CommentTree(comment),
detached: true, detached: true,
), ),
fetcher: fetcher,
controller: controller,
noItems: const Text('there are no comments'), noItems: const Text('there are no comments'),
uniqueProp: (item) => item.comment.apId, uniqueProp: (item) => item.comment.apId,
); );

View File

@ -14,14 +14,14 @@ class TileAction extends StatelessWidget {
final Color? iconColor; final Color? iconColor;
const TileAction({ const TileAction({
Key? key, super.key,
this.delayedLoading, this.delayedLoading,
this.iconColor, this.iconColor,
required this.icon, required this.icon,
required this.onPressed, required this.onPressed,
required this.tooltip, required this.tooltip,
this.loading = false, this.loading = false,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) => IconButton( Widget build(BuildContext context) => IconButton(

View File

@ -12,8 +12,8 @@ class PersonTile extends StatelessWidget {
const PersonTile( const PersonTile(
this.person, { this.person, {
this.expanded = false, this.expanded = false,
Key? key, super.key,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {