flutter_autostart

Last updated:

0 purchases

flutter_autostart Image
flutter_autostart Images
Add to Cart

Description:

flutter autostart

Flutter AutoStart #
Flutter AutoStart is a plugin that allows you to manage Android auto-start permissions in your Flutter app.
Installation #


Add the latest version of the package to your pubspec.yaml (and run dart pub get):
dependencies:
flutter_autostart: ^0.0.2
copied to clipboard


Import the package and use it in your Flutter app:
import 'package:flutter_autostart/flutter_autostart.dart';
copied to clipboard


Example #
// ignore_for_file: unused_local_variable, avoid_print

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_autostart/flutter_autostart.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 _flutterAutostartPlugin = FlutterAutostart();

@override
void initState() {
super.initState();
}

Future<void> checkIsAutoStartEnabled() async {
String isAutoStartEnabled;
try {
isAutoStartEnabled = await _flutterAutostartPlugin.checkIsAutoStartEnabled() == true ? "Yes" : "No";
print("isAutoStartEnabled: $isAutoStartEnabled");
} on PlatformException {
isAutoStartEnabled = 'Failed to check isAutoStartEnabled.';
}
if (!mounted) return;
}

Future<void> openAutoStartPermissionSettings() async {
String autoStartPermission;
try {
autoStartPermission =
await _flutterAutostartPlugin.showAutoStartPermissionSettings() ?? 'Unknown autoStartPermission';
} on PlatformException {
autoStartPermission = 'Failed to show autoStartPermission.';
}
if (!mounted) return;
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter AutoStart'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
checkIsAutoStartEnabled();
},
child: const Text("Check is auto-start enabled"),
),
ElevatedButton(
onPressed: () {
openAutoStartPermissionSettings();
},
child: const Text("Request auto-start permission"),
),
],
),
),
),
);
}
}

copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.