Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Fix Dart 2 type error and deprecation #425

Merged
merged 4 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/battery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.1

* Fixed Dart 2 type error.
* Removed use of deprecated parameter in example.

## 0.2.0

* **Breaking change**. Set SDK constraints to match the Flutter beta release.
Expand Down
23 changes: 12 additions & 11 deletions packages/battery/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,20 @@ class _MyHomePageState extends State<MyHomePage> {
floatingActionButton: new FloatingActionButton(
child: const Icon(Icons.battery_unknown),
onPressed: () async {
final int batteryLevel = await _battery.batteryLevel;
showDialog<Null>(
context: context,
child: new AlertDialog(
content: new Text('Battery: ${await _battery.batteryLevel}%'),
actions: <Widget>[
new FlatButton(
child: const Text('OK'),
onPressed: () {
Navigator.pop(context);
},
)
],
),
builder: (_) => new AlertDialog(
content: new Text('Battery: $batteryLevel%'),
actions: <Widget>[
new FlatButton(
child: const Text('OK'),
onPressed: () {
Navigator.pop(context);
},
)
],
),
);
},
),
Expand Down
5 changes: 3 additions & 2 deletions packages/battery/lib/battery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class Battery {
Stream<BatteryState> _onBatteryStateChanged;

/// Returns the current battery level in percent.
Future<int> get batteryLevel =>
_methodChannel.invokeMethod('getBatteryLevel');
Future<int> get batteryLevel => _methodChannel
.invokeMethod('getBatteryLevel')
.then<int>((dynamic result) => result);

/// Fires whenever the battery state changes.
Stream<BatteryState> get onBatteryStateChanged {
Expand Down
2 changes: 1 addition & 1 deletion packages/battery/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for accessing information about the battery state
(full, charging, discharging) on Android and iOS.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/battery
version: 0.2.0
version: 0.2.1

flutter:
plugin:
Expand Down
44 changes: 25 additions & 19 deletions packages/firebase_messaging/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,38 @@ class _PushMessagingExampleState extends State<PushMessagingExample> {
final TextEditingController _topicController =
new TextEditingController(text: 'topic');

Future<Null> _showItemDialog(Map<String, dynamic> message) async {
final Item item = _itemForMessage(message);
Widget _buildDialog(BuildContext context, Item item) {
return new AlertDialog(
content: new Text("Item ${item.itemId} has been updated"),
actions: <Widget>[
new FlatButton(
child: const Text('CLOSE'),
onPressed: () {
Navigator.pop(context, false);
},
),
new FlatButton(
child: const Text('SHOW'),
onPressed: () {
Navigator.pop(context, true);
},
),
],
);
}

void _showItemDialog(Map<String, dynamic> message) {
showDialog<bool>(
context: context,
child: new AlertDialog(
content: new Text("Item ${item.itemId} has been updated"),
actions: <Widget>[
new FlatButton(
child: const Text('CLOSE'),
onPressed: () {
Navigator.pop(context, false);
}),
new FlatButton(
child: const Text('SHOW'),
onPressed: () {
Navigator.pop(context, true);
}),
],
)).then((bool shouldNavigate) {
context: context,
builder: (_) => _buildDialog(context, _itemForMessage(message)),
).then((bool shouldNavigate) {
if (shouldNavigate == true) {
_navigateToItemDetail(message);
}
});
}

Future<Null> _navigateToItemDetail(Map<String, dynamic> message) async {
void _navigateToItemDetail(Map<String, dynamic> message) {
final Item item = _itemForMessage(message);
// Clear away dialogs
Navigator.popUntil(context, (Route<dynamic> route) => route is PageRoute);
Expand Down