flutter_ignorebatteryoptimization 0.0.1 flutter_ignorebatteryoptimization: ^0.0.1 copied to clipboard
Flutter Ignore Battery Optimization Permission for Andorid Devices :)
// ignore_for_file: unused_local_variable
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_ignorebatteryoptimization/flutter_ignorebatteryoptimization.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> {
final _flutterIgnorebatteryoptimizationPlugin =
FlutterIgnorebatteryoptimization();
@override
void initState() {
super.initState();
}
Future<void> openIgnorebatteryoptimizationPlugin() async {
String ignoreBatteryOptimization;
try {
ignoreBatteryOptimization = await _flutterIgnorebatteryoptimizationPlugin
.showIgnoreBatteryOptimizationSettings() ??
'Unknown ignoreBatteryOptimization';
} on PlatformException {
ignoreBatteryOptimization = 'Failed to show ignoreBatteryOptimization.';
}
if (!mounted) return;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter IgnoreBatteryOptimization'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
openIgnorebatteryoptimizationPlugin();
},
child: const Text(
"Request ignore-battery-optimization permission"),
),
],
),
),
),
);
}
}