A Flutter plugin to help implementing custom eco-friendly mode in your mobile app.
According to our recommendations, the plugin determine if a device is:
- a low-end device
- in a battery eco mode
It will also give you your own rules for your app.
This plugin is still in reflexion and development. And will only be available for Android and iOS at the moment.
Next this plugin will have the objective to propose solutions to deactivate functionalities of the device to save energy. For example, disable animations or other nonessential resourceful operations...
We are developing this plugin, to perhaps implementing it on the SNCF Connect application, and offering an eco-friendly app to our users who have low-end devices to allow them to save the resources of their phone. And also to offer a less energy-consuming app.
Feature | Android | iOS | Runtime | Event |
---|---|---|---|---|
Platform Info | Yes | Yes | X | |
Processor Count | Yes | Yes | X | |
Total Memory | Yes | Yes | X | |
Free Memory | Yes | Yes | X | |
Total Storage | Yes | Yes | X | |
Free Storage | Yes | Yes | X | |
Device Range | Yes | Yes | X | X |
Battery Thermal State | Yes | Yes | X | |
Battery State | Yes | Yes | X | X |
Battery Level | Yes | Yes | X | X |
Battery In Low Power Mode | Yes | Yes | X | X |
Battery Eco Mode | Yes | Yes | X | X |
Connectivity | Yes | No | X | X |
This feature gives the possibility to calculate a score for the device. The score does NOT represent an ecological performance. It's just a score to determine the device's capacities. It is calculated by combining static information about the device on different OS. It will return a double between 0 and 1.
Then we can determine the device Eco Range:
- High End
- Mid Range
- Low End
Low-end devices means devices with poor capacities or poor features, usually old devices or low-cost devices.
And finally, you can use the last boolean information isLowEndDevice to directly know if your device is a low-end device or not.
That's why we give you the possibility to calculate your own score by using others features in the plugin. If you have more than three eco ranges in your custom eco-mode, feel free to give the best user eco experience to your final users :)
This feature combines different battery information to determine if the device is in eco-mode or not. It will return a boolean.
@override
Stream<bool?> get isBatteryEcoModeStream => CombineLatestStream.list([
_isNotEnoughBatteryStream(),
lowPowerModeEventStream.withInitialValue(isBatteryInLowPowerMode()),
]).map((event) => event.any((element) => element)).asBroadcastStream();
Stream<bool> _isNotEnoughBatteryStream() => CombineLatestStream.list([
batteryLevelEventStream.map((event) => event.isNotEnough),
batteryStateEventStream.map((event) => event.isDischarging),
]).map((event) => event.every((element) => element)).asBroadcastStream();
This feature can help you to observe the network, know if the device is connected to the internet, or just want to adapt your app to the network state.
We have created a class Connectivity which contains basic information about the network.
And you can use directly the methode hasEnoughNetwork which follows these rules in the code
extension on Connectivity {
bool? get isEnough => type == ConnectivityType.unknown
? null
: (_isMobileEnoughNetwork || _isWifiEnoughNetwork || type == ConnectivityType.ethernet);
bool get _isMobileEnoughNetwork =>
[ConnectivityType.mobile5g, ConnectivityType.mobile4g, ConnectivityType.mobile3g].contains(type);
bool get _isWifiEnoughNetwork =>
ConnectivityType.wifi == type && wifiSignalStrength != null ? wifiSignalStrength! >= minWifiSignalStrength : false;
}
- First, we retrieve the type of network via native access.
- Then, if we have Wifi identified we catch the signal strength.
- And finally, we build and return the object Connectivity.
At this moment, you can ask your self. Is it really reliable ? Is there a better way ?
Probably the better thing to do is to make your own speed test in your app. You're right, it's more precise, and you can directly define what is a good network fo your purposes. But you need to ping a server, and it's not really eco-friendly. Here we just use the native access, trust directly your device and OS.
See the example
directory for a complete sample app using flutter_eco_mode.
We are open to any contributions or suggestions. If you have any questions, please contact us.
Copyright © 2024 SNCF Connect & Tech. This project is licensed under the MIT License - see the LICENSE file for details.
This file has been written on February 22, 2024.