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

Migrate from deprecated pedantic to flutter_lints #519

Merged
merged 9 commits into from
Oct 6, 2021
12 changes: 6 additions & 6 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
#
# include: ../../analysis_options.yaml
#
include: package:pedantic/analysis_options.yaml
include: package:flutter_lints/flutter.yaml

analyzer:
enable-experiment:
- non-nullable
exclude:
# Ignore generated files
- '**/*.g.dart'
- 'lib/src/generated/*.dart'

errors:
avoid_print: ignore

linter:
rules:
public_member_api_docs: true
prefer_final_in_for_each: true
prefer_final_locals: true
- prefer_final_in_for_each
- prefer_final_locals
2 changes: 1 addition & 1 deletion melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ scripts:
melos exec -c 6 -- "flutter clean"

dev_dependencies:
pedantic: 1.10.0
flutter_lints: 1.0.4

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
15 changes: 9 additions & 6 deletions packages/android_alarm_manager_plus/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final ReceivePort port = ReceivePort();
SharedPreferences prefs;

Future<void> main() async {
// ignore: todo
// TODO(bkonyi): uncomment
WidgetsFlutterBinding.ensureInitialized();

Expand All @@ -38,23 +39,25 @@ Future<void> main() async {
if (!prefs.containsKey(countKey)) {
await prefs.setInt(countKey, 0);
}
runApp(AlarmManagerExampleApp());
runApp(const AlarmManagerExampleApp());
}

/// Example app for Espresso plugin.
class AlarmManagerExampleApp extends StatelessWidget {
const AlarmManagerExampleApp({Key key}) : super(key: key);

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
return const MaterialApp(
title: 'Flutter Demo',
home: _AlarmHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class _AlarmHomePage extends StatefulWidget {
_AlarmHomePage({Key key, this.title}) : super(key: key);
const _AlarmHomePage({Key key, this.title}) : super(key: key);
final String title;

@override
Expand Down Expand Up @@ -126,13 +129,13 @@ class _AlarmHomePageState extends State<_AlarmHomePage> {
),
Text(
prefs.getInt(countKey).toString(),
key: ValueKey('BackgroundCountText'),
key: const ValueKey('BackgroundCountText'),
style: textStyle,
),
],
),
ElevatedButton(
key: ValueKey('RegisterOneShotAlarm'),
key: const ValueKey('RegisterOneShotAlarm'),
onPressed: () async {
await AndroidAlarmManager.oneShot(
const Duration(seconds: 5),
Expand All @@ -143,7 +146,7 @@ class _AlarmHomePageState extends State<_AlarmHomePage> {
wakeup: true,
);
},
child: Text(
child: const Text(
'Schedule OneShot Alarm',
),
),
Expand Down
2 changes: 1 addition & 1 deletion packages/android_alarm_manager_plus/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dev_dependencies:
sdk: flutter
flutter_test:
sdk: flutter
pedantic: ^1.9.2
flutter_lints: ^1.0.4

flutter:
uses-material-design: true
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void main() {

group('oneshot', () {
testWidgets('cancelled before it fires', (WidgetTester tester) async {
final alarmId = 0;
const alarmId = 0;
final startingValue = await readCounter();
debugPrint('oneShot start');
await AndroidAlarmManager.oneShot(
Expand All @@ -78,7 +78,7 @@ void main() {
});

testWidgets('cancelled after it fires', (WidgetTester tester) async {
final alarmId = 1;
const alarmId = 1;
final startingValue = await readCounter();
debugPrint('oneShot start');
await AndroidAlarmManager.oneShot(
Expand All @@ -100,7 +100,7 @@ void main() {
});

testWidgets('periodic', (WidgetTester tester) async {
final alarmId = 2;
const alarmId = 2;
final startingValue = await readCounter();
await AndroidAlarmManager.periodic(
const Duration(seconds: 1), alarmId, incrementCounter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ typedef _GetCallbackHandle = CallbackHandle? Function(Function callback);
class AndroidAlarmManager {
static const String _channelName =
'dev.fluttercommunity.plus/android_alarm_manager';
static final MethodChannel _channel =
const MethodChannel(_channelName, JSONMethodCodec());
static const MethodChannel _channel =
MethodChannel(_channelName, JSONMethodCodec());

// Function used to get the current time. It's [DateTime.now] by default.
// ignore: prefer_function_declarations_over_variables
static _Now _now = () => DateTime.now();

// Callback used to get the handle for a callback. It's
// [PluginUtilities.getCallbackHandle] by default.
// ignore: prefer_function_declarations_over_variables
static _GetCallbackHandle _getCallbackHandle =
(Function callback) => PluginUtilities.getCallbackHandle(callback);

Expand Down
2 changes: 1 addition & 1 deletion packages/android_alarm_manager_plus/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
pedantic: ^1.10.0
flutter_lints: ^1.0.4

flutter:
plugin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter_test/flutter_test.dart';

void main() {
String invalidCallback(String foo) => foo;
// ignore: avoid_returning_null_for_void
void validCallback(int id) => null;

const testChannel = MethodChannel(
Expand All @@ -34,7 +35,7 @@ void main() {
group('${AndroidAlarmManager.oneShotAt}', () {
test('validates input', () async {
final validTime = DateTime.utc(1993);
final validId = 1;
const validId = 1;

// Callback should take a single int param.
await expectLater(
Expand All @@ -56,12 +57,12 @@ void main() {
getCallbackHandle: (Function _) =>
CallbackHandle.fromRawHandle(rawHandle));

final id = 1;
final alarmClock = true;
final allowWhileIdle = true;
final exact = true;
final wakeup = true;
final rescheduleOnReboot = true;
const id = 1;
const alarmClock = true;
const allowWhileIdle = true;
const exact = true;
const wakeup = true;
const rescheduleOnReboot = true;

testChannel.setMockMethodCallHandler((MethodCall call) async {
expect(call.method, 'Alarm.oneShotAt');
Expand Down Expand Up @@ -97,12 +98,12 @@ void main() {
CallbackHandle.fromRawHandle(rawHandle));

const alarm = Duration(seconds: 1);
final id = 1;
final alarmClock = true;
final allowWhileIdle = true;
final exact = true;
final wakeup = true;
final rescheduleOnReboot = true;
const id = 1;
const alarmClock = true;
const allowWhileIdle = true;
const exact = true;
const wakeup = true;
const rescheduleOnReboot = true;

testChannel.setMockMethodCallHandler((MethodCall call) async {
expect(call.method, 'Alarm.oneShotAt');
Expand Down Expand Up @@ -131,7 +132,7 @@ void main() {
group('${AndroidAlarmManager.periodic}', () {
test('validates input', () async {
const validDuration = Duration(seconds: 0);
final validId = 1;
const validId = 1;

// Callback should take a single int param.
await expectLater(
Expand All @@ -154,11 +155,11 @@ void main() {
getCallbackHandle: (Function _) =>
CallbackHandle.fromRawHandle(rawHandle));

final id = 1;
final allowWhileIdle = true;
final exact = true;
final wakeup = true;
final rescheduleOnReboot = true;
const id = 1;
const allowWhileIdle = true;
const exact = true;
const wakeup = true;
const rescheduleOnReboot = true;
const period = Duration(seconds: 1);

testChannel.setMockMethodCallHandler((MethodCall call) async {
Expand Down Expand Up @@ -190,7 +191,7 @@ void main() {
});

test('${AndroidAlarmManager.cancel}', () async {
final id = 1;
const id = 1;
testChannel.setMockMethodCallHandler((MethodCall call) async {
assert(call.method == 'Alarm.cancel' && call.arguments[0] == id);
return true;
Expand Down
13 changes: 3 additions & 10 deletions packages/android_intent_plus/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# TODO: Remove this when migrated to null safety
include: package:pedantic/analysis_options.yaml

analyzer:
exclude:
# Ignore generated files
- '**/*.g.dart'
- 'lib/src/generated/*.dart'
include: package:flutter_lints/flutter.yaml

linter:
rules:
public_member_api_docs: true
prefer_final_in_for_each: true
prefer_final_locals: true
- prefer_final_in_for_each
- prefer_final_locals
19 changes: 12 additions & 7 deletions packages/android_intent_plus/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import 'package:flutter/material.dart';
import 'package:platform/platform.dart';

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

/// A sample app for launching intents.
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
Expand All @@ -21,7 +23,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
home: const MyHomePage(),
routes: <String, WidgetBuilder>{
ExplicitIntentsWidget.routeName: (BuildContext context) =>
const ExplicitIntentsWidget()
Expand All @@ -32,8 +34,10 @@ class MyApp extends StatelessWidget {

/// Holds the different intent widgets.
class MyHomePage extends StatelessWidget {
const MyHomePage({Key key}) : super(key: key);

void _createAlarm() {
final intent = const AndroidIntent(
const intent = AndroidIntent(
action: 'android.intent.action.SET_ALARM',
arguments: <String, dynamic>{
'android.intent.extra.alarm.DAYS': <int>[2, 3, 4, 5, 6],
Expand Down Expand Up @@ -91,7 +95,7 @@ class MyHomePage extends StatelessWidget {
}

void _openChooser() {
final intent = const AndroidIntent(
const intent = AndroidIntent(
action: 'android.intent.action.SEND',
type: 'plain/text',
data: 'text example',
Expand All @@ -100,7 +104,7 @@ class MyHomePage extends StatelessWidget {
}

void _sendBroadcast() {
final intent = const AndroidIntent(
const intent = AndroidIntent(
action: 'com.example.broadcast',
);
intent.sendBroadcast();
Expand All @@ -109,6 +113,7 @@ class MyHomePage extends StatelessWidget {

/// Launches intents to specific Android activities.
class ExplicitIntentsWidget extends StatelessWidget {
// ignore: use_key_in_widget_constructors
const ExplicitIntentsWidget(); // ignore: public_member_api_docs

// ignore: public_member_api_docs
Expand Down Expand Up @@ -165,14 +170,14 @@ class ExplicitIntentsWidget extends StatelessWidget {
}

void _openLocationSettingsConfiguration() {
final intent = const AndroidIntent(
const AndroidIntent intent = AndroidIntent(
action: 'action_location_source_settings',
);
intent.launch();
}

void _openApplicationDetails() {
final intent = const AndroidIntent(
const intent = AndroidIntent(
action: 'action_application_details_settings',
data: 'package:io.flutter.plugins.androidintentexample',
);
Expand Down
2 changes: 1 addition & 1 deletion packages/android_intent_plus/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dev_dependencies:
sdk: flutter
integration_test:
sdk: flutter
pedantic: ^1.8.0
flutter_lints: ^1.0.4

# The following section is specific to Flutter.
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('Embedding example app loads', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());
await tester.pumpWidget(const MyApp());

// Verify that the new embedding example app builds
if (Platform.isAndroid) {
Expand Down Expand Up @@ -50,7 +50,7 @@ void main() {
}, skip: !Platform.isAndroid);

testWidgets('#launchChooser should not throw', (WidgetTester tester) async {
final intent = const AndroidIntent(
const intent = AndroidIntent(
action: 'android.intent.action.SEND',
type: 'plain/text',
data: 'text example',
Expand All @@ -59,15 +59,15 @@ void main() {
}, skip: !Platform.isAndroid);

testWidgets('#sendBroadcast should not throw', (WidgetTester tester) async {
final intent = const AndroidIntent(
const intent = AndroidIntent(
action: 'com.example.broadcast',
);
await intent.sendBroadcast();
}, skip: !Platform.isAndroid);

testWidgets('#canResolveActivity returns true when example Activity is found',
(WidgetTester tester) async {
final intent = AndroidIntent(
const intent = AndroidIntent(
action: 'action_view',
package: 'io.flutter.plugins.androidintentexample',
componentName: 'io.flutter.plugins.androidintentexample.MainActivity',
Expand Down
Loading