Enable some extra lints for compass app client (#2560)

Enable a few more lints that were mostly followed already for
consistency.
pull/2564/head
Parker Lougheed 3 weeks ago committed by GitHub
parent e36c642199
commit e39638ebff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,4 +2,10 @@ include: package:flutter_lints/flutter.yaml
linter:
rules:
- combinators_ordering
- directives_ordering
- omit_local_variable_types
- prefer_final_fields
- prefer_final_in_for_each
- prefer_final_locals
- prefer_relative_imports

@ -2,24 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:provider/single_child_widget.dart';
import 'package:provider/provider.dart';
import 'package:provider/single_child_widget.dart';
import '../data/repositories/activity/activity_repository.dart';
import '../data/repositories/activity/activity_repository_local.dart';
import '../data/repositories/activity/activity_repository_remote.dart';
import '../data/repositories/auth/auth_repository.dart';
import '../data/repositories/auth/auth_repository_dev.dart';
import '../data/repositories/auth/auth_repository_remote.dart';
import '../data/repositories/booking/booking_repository.dart';
import '../data/repositories/booking/booking_repository_local.dart';
import '../data/repositories/booking/booking_repository_remote.dart';
import '../data/repositories/user/user_repository.dart';
import '../data/repositories/user/user_repository_local.dart';
import '../data/repositories/user/user_repository_remote.dart';
import '../data/services/api/auth_api_client.dart';
import '../data/services/local/local_data_service.dart';
import '../data/services/shared_preferences_service.dart';
import '../data/repositories/activity/activity_repository.dart';
import '../data/repositories/activity/activity_repository_local.dart';
import '../data/repositories/activity/activity_repository_remote.dart';
import '../data/repositories/continent/continent_repository.dart';
import '../data/repositories/continent/continent_repository_local.dart';
import '../data/repositories/continent/continent_repository_remote.dart';
@ -28,7 +22,13 @@ import '../data/repositories/destination/destination_repository_local.dart';
import '../data/repositories/destination/destination_repository_remote.dart';
import '../data/repositories/itinerary_config/itinerary_config_repository.dart';
import '../data/repositories/itinerary_config/itinerary_config_repository_memory.dart';
import '../data/repositories/user/user_repository.dart';
import '../data/repositories/user/user_repository_local.dart';
import '../data/repositories/user/user_repository_remote.dart';
import '../data/services/api/api_client.dart';
import '../data/services/api/auth_api_client.dart';
import '../data/services/local/local_data_service.dart';
import '../data/services/shared_preferences_service.dart';
import '../domain/use_cases/booking/booking_create_use_case.dart';
import '../domain/use_cases/booking/booking_share_use_case.dart';

@ -23,7 +23,7 @@ class BookingRepositoryRemote implements BookingRepository {
@override
Future<Result<void>> createBooking(Booking booking) async {
try {
final BookingApiModel bookingApiModel = BookingApiModel(
final bookingApiModel = BookingApiModel(
startDate: booking.startDate,
endDate: booking.endDate,
name: '${booking.destination.name}, ${booking.destination.continent}',

@ -22,7 +22,7 @@ class ApiClient {
HttpClient Function()? clientFactory,
}) : _host = host ?? 'localhost',
_port = port ?? 8080,
_clientFactory = clientFactory ?? (() => HttpClient());
_clientFactory = clientFactory ?? HttpClient.new;
final String _host;
final int _port;

@ -16,7 +16,7 @@ class AuthApiClient {
HttpClient Function()? clientFactory,
}) : _host = host ?? 'localhost',
_port = port ?? 8080,
_clientFactory = clientFactory ?? (() => HttpClient());
_clientFactory = clientFactory ?? HttpClient.new;
final String _host;
final int _port;

@ -48,12 +48,12 @@ class LocalDataService {
Future<List<Activity>> getActivities() async {
final json = await _loadStringAsset(Assets.activities);
return json.map<Activity>((json) => Activity.fromJson(json)).toList();
return json.map<Activity>(Activity.fromJson).toList();
}
Future<List<Destination>> getDestinations() async {
final json = await _loadStringAsset(Assets.destinations);
return json.map<Destination>((json) => Destination.fromJson(json)).toList();
return json.map<Destination>(Destination.fromJson).toList();
}
Future<List<Map<String, dynamic>>> _loadStringAsset(String asset) async {

@ -6,8 +6,8 @@ import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:share_plus/share_plus.dart';
import '../../../utils/result.dart';
import '../../../ui/core/ui/date_format_start_end.dart';
import '../../../utils/result.dart';
import '../../models/booking/booking.dart';
typedef ShareFunction = Future<void> Function(String text);

@ -2,16 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'main_development.dart' as development;
import 'routing/router.dart';
import 'ui/core/localization/applocalization.dart';
import 'ui/core/themes/theme.dart';
import 'routing/router.dart';
import 'package:flutter/material.dart';
import 'ui/core/ui/scroll_behavior.dart';
import 'main_development.dart' as development;
/// Default main method
void main() {

@ -11,8 +11,8 @@ import '../ui/activities/view_models/activities_viewmodel.dart';
import '../ui/activities/widgets/activities_screen.dart';
import '../ui/auth/login/view_models/login_viewmodel.dart';
import '../ui/auth/login/widgets/login_screen.dart';
import '../ui/booking/widgets/booking_screen.dart';
import '../ui/booking/view_models/booking_viewmodel.dart';
import '../ui/booking/widgets/booking_screen.dart';
import '../ui/home/view_models/home_viewmodel.dart';
import '../ui/home/widgets/home_screen.dart';
import '../ui/results/view_models/results_viewmodel.dart';
@ -137,8 +137,8 @@ GoRouter router(
// From https://github.com/flutter/packages/blob/main/packages/go_router/example/lib/redirection.dart
Future<String?> _redirect(BuildContext context, GoRouterState state) async {
// if the user is not logged in, they need to login
final bool loggedIn = await context.read<AuthRepository>().isAuthenticated;
final bool loggingIn = state.matchedLocation == Routes.login;
final loggedIn = await context.read<AuthRepository>().isAuthenticated;
final loggingIn = state.matchedLocation == Routes.login;
if (!loggedIn) {
return Routes.login;
}

@ -21,7 +21,7 @@ class LogoutViewModel {
late Command0 logout;
Future<Result> _logout() async {
var result = await _authLogoutRepository.logout();
final result = await _authLogoutRepository.logout();
switch (result) {
case Ok<void>():
// clear stored itinerary config

@ -9,10 +9,10 @@ import '../../../data/repositories/booking/booking_repository.dart';
import '../../../data/repositories/itinerary_config/itinerary_config_repository.dart';
import '../../../domain/models/booking/booking.dart';
import '../../../domain/models/itinerary_config/itinerary_config.dart';
import '../../../utils/command.dart';
import '../../../utils/result.dart';
import '../../../domain/use_cases/booking/booking_create_use_case.dart';
import '../../../domain/use_cases/booking/booking_share_use_case.dart';
import '../../../utils/command.dart';
import '../../../utils/result.dart';
class BookingViewModel extends ChangeNotifier {
BookingViewModel({

@ -29,8 +29,8 @@ abstract final class Dimens {
EdgeInsets get edgeInsetsScreenSymmetric => EdgeInsets.symmetric(
horizontal: paddingScreenHorizontal, vertical: paddingScreenVertical);
static final Dimens desktop = _DimensDesktop();
static final Dimens mobile = _DimensMobile();
static const Dimens desktop = _DimensDesktop();
static const Dimens mobile = _DimensMobile();
/// Get dimensions definition based on screen size
factory Dimens.of(BuildContext context) =>
@ -50,6 +50,8 @@ final class _DimensMobile extends Dimens {
@override
final double profilePictureSize = 64.0;
const _DimensMobile();
}
/// Desktop/Web dimensions
@ -62,4 +64,6 @@ final class _DimensDesktop extends Dimens {
@override
final double profilePictureSize = 128.0;
const _DimensDesktop();
}

@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'colors.dart';
import '../ui/tag_chip.dart';
import 'package:flutter/material.dart';
import '../ui/tag_chip.dart';
import 'colors.dart';
abstract final class AppTheme {
static const _textTheme = TextTheme(
headlineLarge: TextStyle(

@ -80,7 +80,9 @@ class _QueryText extends StatelessWidget {
}
return Text(
'$continent - ${dateFormatStartEnd(DateTimeRange(start: startDate, end: endDate))} - Guests: $guests',
'$continent - '
'${dateFormatStartEnd(DateTimeRange(start: startDate, end: endDate))} - '
'Guests: $guests',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge,
);

@ -4,10 +4,11 @@
import 'dart:ui';
import '../themes/colors.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import '../themes/colors.dart';
class TagChip extends StatelessWidget {
const TagChip({
super.key,
@ -96,7 +97,7 @@ class TagChip extends StatelessWidget {
// Note: original Figma file uses Google Sans
// which is not available on GoogleFonts
_textStyle(BuildContext context) => GoogleFonts.openSans(
TextStyle _textStyle(BuildContext context) => GoogleFonts.openSans(
textStyle: TextStyle(
fontWeight: FontWeight.w500,
fontSize: fontSize,

@ -169,11 +169,11 @@ class _Booking extends StatelessWidget {
confirmDismiss: confirmDismiss,
background: Container(
color: AppColors.grey1,
child: Row(
child: const Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(right: Dimens.paddingHorizontal),
padding: EdgeInsets.only(right: Dimens.paddingHorizontal),
child: Icon(Icons.delete),
),
],

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:logging/logging.dart';
import '../../../data/repositories/destination/destination_repository.dart';
@ -10,7 +11,6 @@ import '../../../domain/models/destination/destination.dart';
import '../../../domain/models/itinerary_config/itinerary_config.dart';
import '../../../utils/command.dart';
import '../../../utils/result.dart';
import 'package:flutter/cupertino.dart';
/// Results screen view model
/// Based on https://docs.flutter.dev/get-started/fwe/state-management#using-mvvm-for-your-applications-architecture

@ -5,9 +5,9 @@
import 'package:flutter/material.dart';
import '../../core/localization/applocalization.dart';
import '../../core/themes/colors.dart';
import '../../core/themes/dimens.dart';
import '../../core/ui/date_format_start_end.dart';
import '../../core/themes/colors.dart';
import '../view_models/search_form_viewmodel.dart';
/// Date selection form field.

@ -10,9 +10,9 @@ import '../../core/themes/dimens.dart';
import '../../core/ui/search_bar.dart';
import '../../results/widgets/results_screen.dart';
import '../view_models/search_form_viewmodel.dart';
import 'search_form_continent.dart';
import 'search_form_date.dart';
import 'search_form_guests.dart';
import 'search_form_continent.dart';
import 'search_form_submit.dart';
/// Search form screen

@ -79,7 +79,7 @@ class Command0<T> extends Command<T> {
/// Executes the action.
Future<void> execute() async {
await _execute(() => _action());
await _execute(_action);
}
}

@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:compass_app/data/repositories/destination/destination_repository_local.dart';
import 'package:compass_app/data/services/local/local_data_service.dart';
import 'package:compass_app/utils/result.dart';
import 'package:compass_app/data/repositories/destination/destination_repository_local.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../testing/utils/result.dart';

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:compass_app/domain/use_cases/booking/booking_create_use_case.dart';
import 'package:compass_app/domain/models/itinerary_config/itinerary_config.dart';
import 'package:compass_app/domain/use_cases/booking/booking_create_use_case.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../testing/fakes/repositories/fake_activities_repository.dart';

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:compass_app/domain/use_cases/booking/booking_share_use_case.dart';
import 'package:compass_app/domain/models/booking/booking.dart';
import 'package:compass_app/domain/use_cases/booking/booking_share_use_case.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../testing/models/activity.dart';

@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:compass_app/domain/models/itinerary_config/itinerary_config.dart';
import 'package:compass_app/domain/use_cases/booking/booking_create_use_case.dart';
import 'package:compass_app/domain/use_cases/booking/booking_share_use_case.dart';
import 'package:compass_app/domain/models/itinerary_config/itinerary_config.dart';
import 'package:compass_app/ui/booking/view_models/booking_viewmodel.dart';
import 'package:compass_app/ui/booking/widgets/booking_screen.dart';
import 'package:flutter/foundation.dart';

@ -37,7 +37,7 @@ void main() {
when(() => goRouter.push(any())).thenAnswer((_) => Future.value(null));
});
loadWidget(WidgetTester tester) async {
Future<void> loadWidget(WidgetTester tester) async {
await testApp(
tester,
ChangeNotifierProvider.value(

@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:compass_app/ui/search_form/view_models/search_form_viewmodel.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:compass_app/ui/search_form/view_models/search_form_viewmodel.dart';
import '../../../../testing/fakes/repositories/fake_continent_repository.dart';
import '../../../../testing/fakes/repositories/fake_itinerary_config_repository.dart';
@ -28,7 +28,7 @@ void main() {
});
test('Setting dateRange updates correctly', () {
final DateTimeRange newDateRange = DateTimeRange(
final newDateRange = DateTimeRange(
start: DateTime(2024, 1, 1),
end: DateTime(2024, 1, 31),
);
@ -59,7 +59,7 @@ void main() {
viewModel.guests = 2;
viewModel.selectedContinent = 'CONTINENT';
final DateTimeRange newDateRange = DateTimeRange(
final newDateRange = DateTimeRange(
start: DateTime(2024, 1, 1),
end: DateTime(2024, 1, 31),
);

@ -4,8 +4,8 @@
import 'package:compass_app/ui/search_form/view_models/search_form_viewmodel.dart';
import 'package:compass_app/ui/search_form/widgets/search_form_date.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../testing/app.dart';
import '../../../../testing/fakes/repositories/fake_continent_repository.dart';

@ -4,8 +4,8 @@
import 'package:compass_app/ui/search_form/view_models/search_form_viewmodel.dart';
import 'package:compass_app/ui/search_form/widgets/search_form_guests.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../../testing/app.dart';
import '../../../../testing/fakes/repositories/fake_continent_repository.dart';

@ -45,7 +45,7 @@ void main() {
// Fill in data
viewModel.guests = 2;
viewModel.selectedContinent = 'CONTINENT';
final DateTimeRange newDateRange = DateTimeRange(
final newDateRange = DateTimeRange(
start: DateTime(2024, 1, 1),
end: DateTime(2024, 1, 31),
);

@ -48,7 +48,7 @@ void main() {
});
test('should only run once', () async {
int count = 0;
var count = 0;
final command = Command0<int>(() => Future.value(Result.ok(count++)));
final future = command.execute();

@ -12,7 +12,7 @@ import 'package:mocktail_image_network/mocktail_image_network.dart';
import 'mocks.dart';
testApp(
Future<void> testApp(
WidgetTester tester,
Widget body, {
GoRouter? goRouter,

Loading…
Cancel
Save