launch_at_startup 0.3.0 launch_at_startup: ^0.3.0 copied to clipboard
This plugin allows Flutter desktop apps to Auto launch on startup / login.
import 'dart:io';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:launch_at_startup/launch_at_startup.dart';
import 'package:package_info_plus/package_info_plus.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
if (!kIsWeb) {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
launchAtStartup.setup(
appName: packageInfo.appName,
appPath: Platform.resolvedExecutable,
packageName: 'dev.leanflutter.examples.launchatstartupexample',
);
}
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
builder: BotToastInit(),
navigatorObservers: [BotToastNavigatorObserver()],
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool _isEnabled = false;
@override
void initState() {
super.initState();
_init();
}
_init() async {
_isEnabled = await launchAtStartup.isEnabled();
setState(() {});
}
_handleEnable() async {
await launchAtStartup.enable();
await _init();
}
_handleDisable() async {
await launchAtStartup.disable();
await _init();
}
Widget _buildBody(BuildContext context) {
return ListView(
children: <Widget>[
ListTile(
title: const Text('enable'),
onTap: _handleEnable,
),
ListTile(
title: const Text('disable'),
onTap: _handleDisable,
),
ListTile(
title: const Text('isEnabled'),
trailing: Text('$_isEnabled'),
),
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: _buildBody(context),
);
}
}