Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retire pedantic in favor of flutter_lints #210

Merged
merged 9 commits into from Jan 17, 2024
89 changes: 89 additions & 0 deletions analysis_options.yaml
@@ -0,0 +1,89 @@
include: package:flutter_lints/flutter.yaml

analyzer:
language:
strict-casts: true
strict-raw-types: true
errors:
deprecated_member_use_from_same_package: ignore

linter:
rules:
- annotate_overrides
- avoid_annotating_with_dynamic
- avoid_empty_else
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_relative_lib_imports
- avoid_renaming_method_parameters
- avoid_return_types_on_setters
- avoid_returning_null_for_void
- avoid_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
- avoid_types_as_parameter_names
- await_only_futures
- camel_case_extensions
- camel_case_types
- constant_identifier_names
- control_flow_in_finally
- curly_braces_in_flow_control_structures
- depend_on_referenced_packages
- empty_catches
- empty_constructor_bodies
- empty_statements
- exhaustive_cases
- file_names
- library_names
- library_prefixes
- library_private_types_in_public_api
- no_duplicate_case_values
- no_leading_underscores_for_library_prefixes
- no_leading_underscores_for_local_identifiers
- non_constant_identifier_names
- null_check_on_nullable_type_parameter
- null_closures
- overridden_fields
- package_names
- package_prefixed_library_names
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_contains
- prefer_final_fields
- prefer_for_elements_to_map_fromIterable
- prefer_function_declarations_over_variables
- prefer_if_null_operators
- prefer_initializing_formals
- prefer_inlined_adds
- prefer_interpolation_to_compose_strings
- prefer_is_empty
- prefer_is_not_empty
- prefer_is_not_operator
- prefer_iterable_whereType
- prefer_null_aware_operators
- prefer_spread_collections
- prefer_typing_uninitialized_variables
- prefer_void_to_null
- provide_deprecation_message
- recursive_getters
- slash_for_doc_comments
- type_init_formals
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_constructor_name
- unnecessary_getters_setters
- unnecessary_late
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_in_if_null_operators
- unnecessary_nullable_for_final_variable_declarations
- unnecessary_overrides
- unnecessary_string_escapes
- unnecessary_string_interpolations
- unnecessary_this
- unrelated_type_equality_checks
- use_function_type_syntax_for_parameters
- use_rethrow_when_possible
- valid_regexps
- void_checks
1 change: 1 addition & 0 deletions pay/analysis_options.yaml
@@ -0,0 +1 @@
include: ../analysis_options.yaml
1 change: 1 addition & 0 deletions pay/example/analysis_options.yaml
@@ -0,0 +1 @@
include: ../../analysis_options.yaml
16 changes: 9 additions & 7 deletions pay/example/lib/main.dart
Expand Up @@ -19,7 +19,7 @@ import 'package:pay/pay.dart';
import 'payment_configurations.dart' as payment_configurations;

void main() {
runApp(PayMaterialApp());
runApp(const PayMaterialApp());
}

const _paymentItems = [
Expand All @@ -31,29 +31,31 @@ const _paymentItems = [
];

class PayMaterialApp extends StatelessWidget {
const PayMaterialApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
return const MaterialApp(
title: 'Pay for Flutter Demo',
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''),
const Locale('es', ''),
const Locale('de', ''),
Locale('en', ''),
Locale('es', ''),
Locale('de', ''),
],
home: PaySampleApp(),
);
}
}

class PaySampleApp extends StatefulWidget {
PaySampleApp({Key? key}) : super(key: key);
const PaySampleApp({Key? key}) : super(key: key);

@override
_PaySampleAppState createState() => _PaySampleAppState();
State<PaySampleApp> createState() => _PaySampleAppState();
}

class _PaySampleAppState extends State<PaySampleApp> {
Expand Down
5 changes: 5 additions & 0 deletions pay/example/pubspec.yaml
Expand Up @@ -29,6 +29,8 @@ flutter:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
pay:
path: ../

Expand All @@ -45,5 +47,8 @@ dependency_overrides:
path: ../../pay_platform_interface

dev_dependencies:
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
flutter_lints: ^2.0.2
6 changes: 3 additions & 3 deletions pay/lib/src/pay.dart
Expand Up @@ -27,7 +27,7 @@ class Pay {
Map<PayProvider, PaymentConfiguration>? _configurations;

// Future to keep track of asynchronous initialization items.
Future? _assetInitializationFuture;
Future<void>? _assetInitializationFuture;

/// Creates an instance with a dictionary of [_configurations] and
/// instantiates the [_payPlatform] to communicate with the native platforms.
Expand All @@ -43,7 +43,7 @@ class Pay {
}

/// Load the list of configurations from the assets.
Future _loadConfigAssets(List<String> configurationAssets) async =>
Future<void> _loadConfigAssets(List<String> configurationAssets) async =>
_configurations = Map.fromEntries(await Future.wait(configurationAssets
.map((ca) => PaymentConfiguration.fromAsset(ca))
.map((c) async => MapEntry(((await c).provider), await c))));
Expand Down Expand Up @@ -78,7 +78,7 @@ class Pay {

/// Verifies that the selected provider has been previously configured or
/// throws otherwise.
Future throwIfProviderIsNotDefined(PayProvider provider) async {
Future<void> throwIfProviderIsNotDefined(PayProvider provider) async {
await _assetInitializationFuture;
if (!_configurations!.containsKey(provider)) {
throw ProviderNotConfiguredException(
Expand Down
5 changes: 3 additions & 2 deletions pay/lib/src/widgets/google_pay_button.dart
Expand Up @@ -24,8 +24,9 @@ class GooglePayButton extends PayButton {

GooglePayButton({
Key? key,
@Deprecated('Prefer to use [paymentConfiguration]. Take a look at the readme to see examples')
String? paymentConfigurationAsset,
@Deprecated(
'Prefer to use [paymentConfiguration]. Take a look at the readme to see examples')
String? paymentConfigurationAsset,
PaymentConfiguration? paymentConfiguration,
required void Function(Map<String, dynamic> result) onPaymentResult,
required List<PaymentItem> paymentItems,
Expand Down
9 changes: 5 additions & 4 deletions pay/lib/src/widgets/pay_button.dart
Expand Up @@ -55,8 +55,9 @@ abstract class PayButton extends StatefulWidget {
PayButton(
Key? key,
this.buttonProvider,
@Deprecated('Prefer to use [paymentConfiguration]. Take a look at the readme to see examples')
final String? paymentConfigurationAsset,
@Deprecated(
'Prefer to use [paymentConfiguration]. Take a look at the readme to see examples')
final String? paymentConfigurationAsset,
final PaymentConfiguration? paymentConfiguration,
this.onPaymentResult,
this.width,
Expand Down Expand Up @@ -103,7 +104,7 @@ abstract class PayButton extends StatefulWidget {
_supportedPlatforms.contains(defaultTargetPlatform);

@override
_PayButtonState createState() => _PayButtonState();
State<PayButton> createState() => _PayButtonState();
}

/// Button state that adds the widgets to the tree and holds the result of the
Expand Down Expand Up @@ -173,7 +174,7 @@ class ButtonPlaceholder extends StatelessWidget {
final Widget? child;
final EdgeInsets margin;

ButtonPlaceholder({
const ButtonPlaceholder({
Key? key,
this.child,
required this.margin,
Expand Down
2 changes: 1 addition & 1 deletion pay/pubspec.yaml
Expand Up @@ -43,4 +43,4 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.0.8
pedantic: ^1.11.0
flutter_lints: ^2.0.2
3 changes: 2 additions & 1 deletion pay/test/pay_test.dart
Expand Up @@ -31,7 +31,8 @@ String _fixtureAsset(String name) {

Future<Map<String, dynamic>> _testProfileLoader(
String paymentConfigurationAsset) async =>
jsonDecode(_fixtureAsset(paymentConfigurationAsset));
jsonDecode(_fixtureAsset(paymentConfigurationAsset))
as Map<String, dynamic>;

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Expand Down
1 change: 1 addition & 0 deletions pay_android/analysis_options.yaml
@@ -0,0 +1 @@
include: ../analysis_options.yaml
4 changes: 2 additions & 2 deletions pay_android/lib/src/widgets/google_pay_button.dart
@@ -1,4 +1,4 @@
/// Copyright 2021 Google LLC
/// Copyright 2023 Google LLC
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -102,7 +102,7 @@ class RawGooglePayButton extends StatelessWidget {
///
/// The path is generated based on the button type and style, and the
/// language code of the [context], and is returned as a [String].
String _assetPath(context) {
String _assetPath(BuildContext context) {
final assetName = '${type.asset}.svg';
if ([GooglePayButtonType.plain].contains(type)) {
return 'assets/$assetName';
Expand Down
2 changes: 1 addition & 1 deletion pay_android/pubspec.yaml
Expand Up @@ -74,4 +74,4 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.0.8
pedantic: ^1.11.0
flutter_lints: ^2.0.2
6 changes: 3 additions & 3 deletions pay_android/test/pay_button_test.dart
@@ -1,4 +1,4 @@
/// Copyright 2021 Google LLC
/// Copyright 2023 Google LLC
/// SPDX-License-Identifier: Apache-2.0

import 'package:flutter/material.dart';
Expand All @@ -13,7 +13,7 @@ void main() {
testWidgets('defaults to type dark', (WidgetTester tester) async {
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: RawGooglePayButton(onPressed: () => null),
child: RawGooglePayButton(onPressed: () {}),
));

expect(
Expand All @@ -30,7 +30,7 @@ void main() {
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: RawGooglePayButton(onPressed: () => null),
child: RawGooglePayButton(onPressed: () {}),
),
),
);
Expand Down
1 change: 1 addition & 0 deletions pay_ios/analysis_options.yaml
@@ -0,0 +1 @@
include: ../analysis_options.yaml
2 changes: 1 addition & 1 deletion pay_ios/pubspec.yaml
Expand Up @@ -36,4 +36,4 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.0.8
pedantic: ^1.11.0
flutter_lints: ^2.0.2
6 changes: 3 additions & 3 deletions pay_ios/test/pay_button_test.dart
@@ -1,4 +1,4 @@
/// Copyright 2021 Google LLC
/// Copyright 2023 Google LLC
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -26,7 +26,7 @@ void main() {
testWidgets('defaults to type plan and black', (WidgetTester tester) async {
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: RawApplePayButton(onPressed: () => null),
child: RawApplePayButton(onPressed: () {}),
));

expect(
Expand All @@ -46,7 +46,7 @@ void main() {
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: RawApplePayButton(onPressed: () => null),
child: RawApplePayButton(onPressed: () {}),
),
),
);
Expand Down
1 change: 1 addition & 0 deletions pay_platform_interface/analysis_options.yaml
@@ -0,0 +1 @@
include: ../analysis_options.yaml
16 changes: 8 additions & 8 deletions pay_platform_interface/lib/core/payment_configuration.dart
Expand Up @@ -56,16 +56,16 @@ class PaymentConfiguration {
PaymentConfiguration._(Map<String, dynamic> configuration)
: assert(configuration.containsKey('provider')),
assert(configuration.containsKey('data')),
assert(PayProviders.isValidProvider(configuration['provider'])),
provider = PayProviders.fromString(configuration['provider'])!,
_parameters = Configurations.buildParameters(
PayProviders.fromString(configuration['provider'])!,
configuration['data']);
assert(
PayProviders.isValidProvider(configuration['provider'] as String)),
provider =
PayProviders.fromString(configuration['provider'] as String)!,
_parameters = Configurations.extractParameters(configuration);

/// Creates a [PaymentConfiguration] object from the
/// [paymentConfigurationString] in JSON format.
PaymentConfiguration.fromJsonString(String paymentConfigurationString)
: this._(jsonDecode(paymentConfigurationString));
: this._(jsonDecode(paymentConfigurationString) as Map<String, dynamic>);

/// Creates a [PaymentConfiguration] object wrapped in a [Future] from a
/// configuration loaded from an external source.
Expand Down Expand Up @@ -97,8 +97,8 @@ class PaymentConfiguration {
/// caller.
static Future<Map<String, dynamic>> _defaultProfileLoader(
String paymentConfigurationAsset) async =>
await rootBundle.loadStructuredData(
'assets/$paymentConfigurationAsset', (s) async => jsonDecode(s));
await rootBundle.loadStructuredData('assets/$paymentConfigurationAsset',
(s) async => jsonDecode(s) as Map<String, dynamic>);

/// Returns the core configuration map in this object.
Future<Map<String, dynamic>> parameterMap() async {
Expand Down
2 changes: 1 addition & 1 deletion pay_platform_interface/lib/core/payment_item.dart
@@ -1,4 +1,4 @@
/// Copyright 2021 Google LLC
/// Copyright 2023 Google LLC
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
Expand Down
9 changes: 5 additions & 4 deletions pay_platform_interface/lib/pay_channel.dart
@@ -1,4 +1,4 @@
/// Copyright 2021 Google LLC
/// Copyright 2023 Google LLC
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,7 +44,8 @@ class PayMethodChannel extends PayPlatform {
@override
Future<bool> userCanPay(PaymentConfiguration paymentConfiguration) async {
return await _channel.invokeMethod(
'userCanPay', jsonEncode(await paymentConfiguration.parameterMap()));
'userCanPay', jsonEncode(await paymentConfiguration.parameterMap()))
as bool;
}

/// Shows the payment selector to complete the payment operation.
Expand All @@ -61,8 +62,8 @@ class PayMethodChannel extends PayPlatform {
final paymentResult = await _channel.invokeMethod('showPaymentSelector', {
'payment_profile': jsonEncode(await paymentConfiguration.parameterMap()),
'payment_items': paymentItems.map((item) => item.toMap()).toList(),
});
}) as String;

return jsonDecode(paymentResult);
return jsonDecode(paymentResult) as Map<String, dynamic>;
}
}