autostart_settings 0.1.4 autostart_settings: ^0.1.4 copied to clipboard
Plugin to check if autostart settings is available for the device and opens the autostart settings
import 'package:flutter/material.dart';
import 'package:autostart_settings/autostart_settings.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _text = '';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Autostart example app'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () async {
final canOpen = await AutostartSettings.canOpen(
autoStart: true, batterySafer: true);
setState(() {
if (canOpen) {
_text = 'device can open autostart Settings';
} else {
_text = 'device doesn\'t have autostart settings activity';
}
});
},
child: const Text('Can open autostart settings')),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () async {
final opened = await AutostartSettings.open(
autoStart: true, batterySafer: true);
setState(() {
_text = 'Settings opened: $opened';
});
},
child: const Text('Open autostart Settings')),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(_text),
)
],
),
),
),
);
}
}