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

[battery] Port battery to use platform interface #2980

Merged
merged 3 commits into from
Sep 1, 2020
Merged

[battery] Port battery to use platform interface #2980

merged 3 commits into from
Sep 1, 2020

Conversation

yash1200
Copy link
Contributor

Description

In this PR, I have ported battery to use battery_platform_package .

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@yash1200
Copy link
Contributor Author

Hey @ditman kindly have a look at this one :)

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

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

This looks great! However the current master is failing a test. I'll merge this once that gets fixed!

@yash1200
Copy link
Contributor Author

yash1200 commented Sep 1, 2020

Sounds good :) Thank you @ditman .

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

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

LGTM, lots of red! Let's merge this. Thanks for the contribution!

@ditman ditman merged commit 854cfd5 into flutter:master Sep 1, 2020
@ditman
Copy link
Member

ditman commented Sep 1, 2020

Tagged and published as battery: ^1.0.5

@yash1200
Copy link
Contributor Author

yash1200 commented Sep 1, 2020

Thank you sir!

@yash1200 yash1200 deleted the battery branch September 1, 2020 19:27
@yash1200
Copy link
Contributor Author

yash1200 commented Sep 1, 2020

Hey @ditman , I had a query, I was working on it's linux version and and for that I don't need to make method call as I can get data by opening 2 files in dart only. For that to work I have to make get methods batteryLevel and onBatteryStateChanged and then override the platform functions in battery_platform_interface to get data, which means I have to rename platform functions to get that working. Am I in right direction or is there some other method to get this working?

@ditman
Copy link
Member

ditman commented Sep 1, 2020

@yash1200 on Linux you just need to implement the calls to the Method Channel of the battery interface in C++, similar to this:

https://github.com/flutter/plugins/blob/master/packages/url_launcher/url_launcher_linux/linux/url_launcher_plugin.cc

No need to override anything on the platform interface.

I hope that helps!

@yash1200
Copy link
Contributor Author

yash1200 commented Sep 2, 2020

Method channel can be implemented in Linux but I don't know about event channels. I couldn't find anything on it on flutter engine docs. That's why I was trying to implement it like this.

This way it can be done using Dart only, as I have to listen to file /sys/class/power_supply/BAT1/status for getting battery status and it can be done in Dart.

@ditman
Copy link
Member

ditman commented Sep 2, 2020

@yash1200 shared_preferences_linux seems to be written in Dart also, you might want to use it as an additional example: https://github.com/flutter/plugins/tree/master/packages/shared_preferences/shared_preferences_linux

What's the problem?

Also, do you think there's a more portable way to check the battery? it seems there can be multiple BATx devices (some blog posts I see BAT0)

@yash1200
Copy link
Contributor Author

yash1200 commented Sep 2, 2020

Thanks for the information @ditman . Just had a little confusion in it and it's resolved now. And for the BATx , there are only two versions of it. This differs with distros. I'll add a check for this in the plugin 😀. Thanks again.

jorgefspereira pushed a commit to jorgefspereira/plugins_flutter that referenced this pull request Oct 10, 2020
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants