batterycapacity 0.0.3 batterycapacity: ^0.0.3 copied to clipboard
A new Flutter project.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:my_plugin/my_plugin.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
double _totalBatteryCapacity = -1;
@override
void initState() {
super.initState();
initBatteryCapacityState();
}
Future<void> initBatteryCapacityState() async {
double? totalBatteryCapacity;
await MyPlugin.batteryCapacity.then((value) {
totalBatteryCapacity = value;
});
if (!mounted) return;
setState(() {
_totalBatteryCapacity = totalBatteryCapacity!;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Battery Capacity Plugin'),
),
body: Center(
child:
Text('Get the total battery capacity: $_totalBatteryCapacity\n'),
),
),
);
}
}