Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Prev Previous commit
Next Next commit
comments
  • Loading branch information
szakarias committed May 3, 2017
commit be94e101040090315fa7f9a7b5a5c2ec8203b6a4
8 changes: 3 additions & 5 deletions packages/path-provider/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,16 @@ class _MyHomePageState extends State<MyHomePage> {

Widget _buildDirectory(
BuildContext context, AsyncSnapshot<Directory> snapshot) {
Text text;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd drop this empty line to make it more apparent that text is defined by the following if.

Text text = const Text('');
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
text = new Text('Error: ${snapshot.error}');
} else if (snapshot.hasData) {
text = new Text('path: ${snapshot.data.path}');
text = new Text('path: ${snapshot.data.path}');
} else {
text = new Text('path unavailable');
text = const Text('path unavailable');
}
} else {
text = new Text('');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new Text(foo) should be const Text(foo) when foo is a constant string.

As an alternatively to the else clause in lines 58-60, you could declare Text text = const Text(''); in line 48.

return new Padding(padding: const EdgeInsets.all(16.0), child: text);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you can extract the new Padding(...) so that appears only once. As in

Widget text;
if (snapshot.hasError)
  text = ...
else if (snapshot.hasData)
  text = ...
else
  text = ...
return new Padding(padding:..., child: text);

Expand Down