From c418bccc79c8e936dedf02c2976ffdfcc7db580f Mon Sep 17 00:00:00 2001 From: Mehmet Fidanboylu Date: Fri, 17 Aug 2018 17:31:43 -0700 Subject: [PATCH] Fix analysis and formatting errors. --- packages/phone_log/example/lib/main.dart | 24 ++++---- packages/phone_log/lib/phone_log.dart | 11 ++-- packages/phone_log/test/phone_log_test.dart | 64 +++++++++++---------- 3 files changed, 53 insertions(+), 46 deletions(-) diff --git a/packages/phone_log/example/lib/main.dart b/packages/phone_log/example/lib/main.dart index 2310058..69ad0af 100644 --- a/packages/phone_log/example/lib/main.dart +++ b/packages/phone_log/example/lib/main.dart @@ -13,10 +13,10 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { Iterable _callRecords; - var phoneLog = new PhoneLog(); + final PhoneLog phoneLog = new PhoneLog(); - Future fetchCallLogs() async { - var callLogs = await phoneLog.getPhoneLogs( + Future fetchCallLogs() async { + final Iterable callLogs = await phoneLog.getPhoneLogs( // startDate: 20180605, duration: 15 seconds startDate: new Int64(1525590000000), duration: new Int64(13)); @@ -26,37 +26,37 @@ class _MyAppState extends State { } void requestPermission() async { - bool res = await phoneLog.requestPermission(); + final bool res = await phoneLog.requestPermission(); print("permission request result is: " + res.toString()); } void checkPermission() async { - PermissionStatus res = await phoneLog.checkPermission(); + final PermissionStatus res = await phoneLog.checkPermission(); print("permission is: " + res.toString()); } @override Widget build(BuildContext context) { - var children = [ + final List children = [ new Padding( padding: const EdgeInsets.all(8.0), child: new RaisedButton( - onPressed: checkPermission, child: new Text("Check permission")), + onPressed: checkPermission, child: const Text("Check permission")), ), new Padding( padding: const EdgeInsets.all(8.0), child: new RaisedButton( onPressed: requestPermission, - child: new Text("Request permission")), + child: const Text("Request permission")), ), new Padding( padding: const EdgeInsets.all(8.0), child: new RaisedButton( - onPressed: fetchCallLogs, child: new Text("Fetch phone log"))), + onPressed: fetchCallLogs, child: const Text("Fetch phone log"))), ]; - for (CallRecord call in _callRecords ?? []) { - children.addAll([ + for (CallRecord call in _callRecords ?? []) { + children.addAll([ new Container( height: 16.0, ), @@ -97,7 +97,7 @@ class _MyAppState extends State { return new MaterialApp( home: new Scaffold( - appBar: new AppBar(title: new Text('PhoneLog plugin example')), + appBar: new AppBar(title: const Text('PhoneLog plugin example')), body: new Center( child: new Column(children: children), ), diff --git a/packages/phone_log/lib/phone_log.dart b/packages/phone_log/lib/phone_log.dart index 6e530e6..d4f9e75 100644 --- a/packages/phone_log/lib/phone_log.dart +++ b/packages/phone_log/lib/phone_log.dart @@ -44,15 +44,16 @@ class PhoneLog { ///The unit of [duration] is second. Future> getPhoneLogs( {Int64 startDate, Int64 duration}) async { - final _startDate = startDate?.toString(); - final _duration = duration?.toString(); - Iterable> records = await _channel.invokeMethod( - 'getPhoneLogs', {"startDate": _startDate, "duration": _duration}); + final String _startDate = startDate?.toString(); + final String _duration = duration?.toString(); + final Iterable> records = await _channel.invokeMethod( + 'getPhoneLogs', + {"startDate": _startDate, "duration": _duration}); return records?.map((Map m) => new CallRecord.fromMap(m)); } } -var permissionMap = { +Map permissionMap = { 'granted': PermissionStatus.granted, 'denied': PermissionStatus.denied, 'deniedAndCannotRequest': PermissionStatus.deniedAndCannotRequest diff --git a/packages/phone_log/test/phone_log_test.dart b/packages/phone_log/test/phone_log_test.dart index 16fa04a..8e345b3 100644 --- a/packages/phone_log/test/phone_log_test.dart +++ b/packages/phone_log/test/phone_log_test.dart @@ -23,28 +23,29 @@ void main() { mockChannelForDenied = new MockPlatformChannel(); mockChannelForDeniedCannotRequest = new MockPlatformChannel(); - when(mockChannel.invokeMethod(typed(any), any)) + when(mockChannel.invokeMethod(any, any)) .thenAnswer((Invocation invocation) { invokedMethod = invocation.positionalArguments[0]; arguments = invocation.positionalArguments[1]; return null; }); - when(mockChannelForGetLogs.invokeMethod('getPhoneLogs', any)) - .thenAnswer((_) => new Future>>(() => [ - { - 'formattedNumber': '123 123 1234', - 'number': '1231231234', - 'callType': 'INCOMING_TYPE', - 'dateYear': 2018, - 'dateMonth': 6, - 'dateDay': 15, - 'dateHour': 3, - 'dateMinute': 16, - 'dateSecond': 23, - 'duration': 123 - } - ])); + when(mockChannelForGetLogs.invokeMethod('getPhoneLogs', any)).thenAnswer( + (_) => + new Future>>(() => >[ + { + 'formattedNumber': '123 123 1234', + 'number': '1231231234', + 'callType': 'INCOMING_TYPE', + 'dateYear': 2018, + 'dateMonth': 6, + 'dateDay': 15, + 'dateHour': 3, + 'dateMinute': 16, + 'dateSecond': 23, + 'duration': 123 + } + ])); when(mockChannelForGranted.invokeMethod('checkPermission', any)) .thenAnswer((_) => new Future(() => 'granted')); @@ -58,13 +59,13 @@ void main() { group('Phone log plugin', () { test('fetch phone log', () async { - var phoneLog = new PhoneLog.private(mockChannelForGetLogs); + final PhoneLog phoneLog = new PhoneLog.private(mockChannelForGetLogs); - var records = await phoneLog.getPhoneLogs( + final Iterable records = await phoneLog.getPhoneLogs( startDate: new Int64(123456789), duration: new Int64(12)); print(records); - var record = records.first; + final CallRecord record = records.first; expect(record.formattedNumber, '123 123 1234'); expect(record.callType, 'INCOMING_TYPE'); @@ -72,41 +73,46 @@ void main() { expect(record.dateYear, 2018); expect(record.duration, 123); - var phoneLogMethod = new PhoneLog.private(mockChannel); + final PhoneLog phoneLogMethod = new PhoneLog.private(mockChannel); await phoneLogMethod.getPhoneLogs( startDate: new Int64(123456789), duration: new Int64(12)); expect(invokedMethod, 'getPhoneLogs'); - expect(arguments, {'startDate': '123456789', 'duration': '12'}); + expect(arguments, + {'startDate': '123456789', 'duration': '12'}); }); test('check permission', () async { - var phoneLog = new PhoneLog.private(mockChannel); + final PhoneLog phoneLog = new PhoneLog.private(mockChannel); await phoneLog.checkPermission(); expect(invokedMethod, 'checkPermission'); expect(arguments, null); - var phoneLogGranted = new PhoneLog.private(mockChannelForGranted); - var permissionGranted = await phoneLogGranted.checkPermission(); + final PhoneLog phoneLogGranted = + new PhoneLog.private(mockChannelForGranted); + final PermissionStatus permissionGranted = + await phoneLogGranted.checkPermission(); expect(permissionGranted, PermissionStatus.granted); - var phoneLogDenied = new PhoneLog.private(mockChannelForDenied); - var permissionDenied = await phoneLogDenied.checkPermission(); + final PhoneLog phoneLogDenied = + new PhoneLog.private(mockChannelForDenied); + final PermissionStatus permissionDenied = + await phoneLogDenied.checkPermission(); expect(permissionDenied, PermissionStatus.denied); - var phoneLogCannotRequest = + final PhoneLog phoneLogCannotRequest = new PhoneLog.private(mockChannelForDeniedCannotRequest); - var permissionCannotRequest = + final PermissionStatus permissionCannotRequest = await phoneLogCannotRequest.checkPermission(); expect(permissionCannotRequest, PermissionStatus.deniedAndCannotRequest); }); test('request permission', () async { - var phoneLog = new PhoneLog.private(mockChannel); + final PhoneLog phoneLog = new PhoneLog.private(mockChannel); await phoneLog.requestPermission();