import

android.os.Build.VERSION

import

android.os.Build.VERSION_CODES

Next, add the following method in the MainActivity class,
below the configureFlutterEngine() method:

private

fun

getBatteryLevel

():

Int

val

batteryLevel

Int

if

VERSION

SDK_INT

>=

VERSION_CODES

LOLLIPOP

val

batteryManager

getSystemService

Context

BATTERY_SERVICE

as

BatteryManager

batteryLevel

batteryManager

getIntProperty

BatteryManager