Skip to content

Commit

Permalink
enable unnecessary_new
Browse files Browse the repository at this point in the history
  • Loading branch information
a14n committed Aug 6, 2018
1 parent ce3a913 commit 76052d6
Show file tree
Hide file tree
Showing 115 changed files with 1,069 additions and 1,096 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ linter:
- unnecessary_const
- unnecessary_getters_setters
# - unnecessary_lambdas # https://github.com/dart-lang/linter/issues/498
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_in_if_null_operators
# - unnecessary_overrides # https://github.com/dart-lang/linter/issues/626 and https://github.com/dart-lang/linter/issues/627
Expand Down
4 changes: 2 additions & 2 deletions packages/android_alarm_manager/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class HelloMessage {
void printHelloMessage(String msg) {
ensureFirebaseUser().then((_) {
firebaseUser.getIdToken().then((String idToken) {
print(new HelloMessage(
new DateTime.now(),
print(HelloMessage(
DateTime.now(),
msg,
Isolate.current.hashCode,
firebaseUser,
Expand Down
4 changes: 2 additions & 2 deletions packages/android_alarm_manager/lib/android_alarm_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AndroidAlarmManager {
bool exact = false,
bool wakeup = false,
}) async {
final int now = new DateTime.now().millisecondsSinceEpoch;
final int now = DateTime.now().millisecondsSinceEpoch;
final int first = now + delay.inMilliseconds;
final String functionName = _nameOfFunction(callback);
if (functionName == null) {
Expand Down Expand Up @@ -84,7 +84,7 @@ class AndroidAlarmManager {
bool exact = false,
bool wakeup = false,
}) async {
final int now = new DateTime.now().millisecondsSinceEpoch;
final int now = DateTime.now().millisecondsSinceEpoch;
final int period = duration.inMilliseconds;
final int first = now + period;
final String functionName = _nameOfFunction(callback);
Expand Down
52 changes: 26 additions & 26 deletions packages/android_intent/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import 'package:flutter/material.dart';
import 'package:platform/platform.dart';

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

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
return MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(),
home: MyHomePage(),
routes: <String, WidgetBuilder>{
ExplicitIntentsWidget.routeName: (BuildContext context) =>
const ExplicitIntentsWidget()
Expand Down Expand Up @@ -51,17 +51,17 @@ class MyHomePage extends StatelessWidget {
Widget build(BuildContext context) {
Widget body;
if (const LocalPlatform().isAndroid) {
body = new Padding(
body = Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0),
child: new Column(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new RaisedButton(
RaisedButton(
child: const Text(
'Tap here to set an alarm\non weekdays at 9:30pm.'),
onPressed: _createAlarm,
),
new RaisedButton(
RaisedButton(
child: const Text('Tap here to test explicit intents.'),
onPressed: () => _openExplicitIntentsView(context)),
],
Expand All @@ -70,11 +70,11 @@ class MyHomePage extends StatelessWidget {
} else {
body = const Text('This plugin only works with Android');
}
return new Scaffold(
appBar: new AppBar(
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: new Center(child: body),
body: Center(child: body),
);
}
}
Expand All @@ -85,23 +85,23 @@ class ExplicitIntentsWidget extends StatelessWidget {
const ExplicitIntentsWidget();

void _openGoogleMapsStreetView() {
final AndroidIntent intent = new AndroidIntent(
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('google.streetview:cbll=46.414382,10.013988'),
package: 'com.google.android.apps.maps');
intent.launch();
}

void _displayMapInGoogleMaps({int zoomLevel = 12}) {
final AndroidIntent intent = new AndroidIntent(
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('geo:37.7749,-122.4194?z=$zoomLevel'),
package: 'com.google.android.apps.maps');
intent.launch();
}

void _launchTurnByTurnNavigationInGoogleMaps() {
final AndroidIntent intent = new AndroidIntent(
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull(
'google.navigation:q=Taronga+Zoo,+Sydney+Australia&avoid=tf'),
Expand All @@ -110,15 +110,15 @@ class ExplicitIntentsWidget extends StatelessWidget {
}

void _openLinkInGoogleChrome() {
final AndroidIntent intent = new AndroidIntent(
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('https://flutter.io'),
package: 'com.android.chrome');
intent.launch();
}

void _testExplicitIntentFallback() {
final AndroidIntent intent = new AndroidIntent(
final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('https://flutter.io'),
package: 'com.android.chrome.implicit.fallback');
Expand All @@ -127,35 +127,35 @@ class ExplicitIntentsWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
return Scaffold(
appBar: AppBar(
title: const Text('Test explicit intents'),
),
body: new Center(
child: new Padding(
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 15.0),
child: new Column(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new RaisedButton(
RaisedButton(
child: const Text(
'Tap here to display panorama\nimagery in Google Street View.'),
onPressed: _openGoogleMapsStreetView,
),
new RaisedButton(
RaisedButton(
child: const Text('Tap here to display\na map in Google Maps.'),
onPressed: _displayMapInGoogleMaps,
),
new RaisedButton(
RaisedButton(
child: const Text(
'Tap here to launch turn-by-turn\nnavigation in Google Maps.'),
onPressed: _launchTurnByTurnNavigationInGoogleMaps,
),
new RaisedButton(
RaisedButton(
child: const Text('Tap here to open link in Google Chrome.'),
onPressed: _openLinkInGoogleChrome,
),
new RaisedButton(
RaisedButton(
child: const Text(
'Tap here to test explicit intent fallback to implicit.'),
onPressed: _testExplicitIntentFallback,
Expand Down
28 changes: 14 additions & 14 deletions packages/battery/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import 'package:flutter/material.dart';
import 'package:battery/battery.dart';

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

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
return MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
Expand All @@ -30,11 +30,11 @@ class MyHomePage extends StatefulWidget {
final String title;

@override
_MyHomePageState createState() => new _MyHomePageState();
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
Battery _battery = new Battery();
Battery _battery = Battery();

BatteryState _batteryState;
StreamSubscription<BatteryState> _batteryStateSubscription;
Expand All @@ -52,23 +52,23 @@ class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: new Center(
child: new Text('$_batteryState'),
body: Center(
child: Text('$_batteryState'),
),
floatingActionButton: new FloatingActionButton(
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.battery_unknown),
onPressed: () async {
final int batteryLevel = await _battery.batteryLevel;
showDialog<Null>(
context: context,
builder: (_) => new AlertDialog(
content: new Text('Battery: $batteryLevel%'),
builder: (_) => AlertDialog(
content: Text('Battery: $batteryLevel%'),
actions: <Widget>[
new FlatButton(
FlatButton(
child: const Text('OK'),
onPressed: () {
Navigator.pop(context);
Expand Down
4 changes: 2 additions & 2 deletions packages/battery/lib/battery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Battery {
const MethodChannel('plugins.flutter.io/battery');
final EventChannel eventChannel =
const EventChannel('plugins.flutter.io/charging');
_instance = new Battery.private(methodChannel, eventChannel);
_instance = Battery.private(methodChannel, eventChannel);
}
return _instance;
}
Expand Down Expand Up @@ -56,6 +56,6 @@ BatteryState _parseBatteryState(String state) {
case 'discharging':
return BatteryState.discharging;
default:
throw new ArgumentError('$state is not a valid BatteryState.');
throw ArgumentError('$state is not a valid BatteryState.');
}
}
12 changes: 6 additions & 6 deletions packages/battery/test/battery_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ void main() {
Battery battery;

setUp(() {
methodChannel = new MockMethodChannel();
eventChannel = new MockEventChannel();
battery = new Battery.private(methodChannel, eventChannel);
methodChannel = MockMethodChannel();
eventChannel = MockEventChannel();
battery = Battery.private(methodChannel, eventChannel);
});

test('batteryLevel', () async {
when(methodChannel.invokeMethod('getBatteryLevel'))
.thenReturn(new Future<int>.value(42));
.thenReturn(Future<int>.value(42));
expect(await battery.batteryLevel, 42);
});

group('battery state', () {
StreamController<String> controller;

setUp(() {
controller = new StreamController<String>();
controller = StreamController<String>();
when(eventChannel.receiveBroadcastStream()).thenReturn(controller.stream);
});

Expand All @@ -48,7 +48,7 @@ void main() {

test('receive values', () async {
final StreamQueue<BatteryState> queue =
new StreamQueue<BatteryState>(battery.onBatteryStateChanged);
StreamQueue<BatteryState>(battery.onBatteryStateChanged);

controller.add("full");
expect(await queue.next, BatteryState.full);
Expand Down
Loading

0 comments on commit 76052d6

Please sign in to comment.