auto_start_flutter 0.1.1 auto_start_flutter: ^0.1.1 copied to clipboard
The plugin redirects the user to auto-start permission screen to allow auto-start and fix background problems in some phones.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:auto_start_flutter/auto_start_flutter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
//call in init state;
initAutoStart();
}
//initializing the autoStart with the first build.
Future<void> initAutoStart() async {
try {
//check auto-start availability.
var test = await (isAutoStartAvailable as FutureOr<bool>);
print(test);
//if available then navigate to auto-start setting page.
if (test) await getAutoStartPermission();
} on PlatformException catch (e) {
print(e);
}
if (!mounted) return;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Auto Start Flutter Example'),
),
body: Center(
child: Text("Auto Start initialize..."),
),
),
);
}
}