launch_at_startup 0.3.1 copy "launch_at_startup: ^0.3.1" to clipboard
launch_at_startup: ^0.3.1 copied to clipboard

This plugin allows Flutter desktop apps to Auto launch on startup / login.

example/lib/main.dart

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),
    );
  }
}
128
likes
155
pub points
95%
popularity

Publisher

verified publisherleanflutter.dev

This plugin allows Flutter desktop apps to Auto launch on startup / login.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, win32_registry

More

Packages that depend on launch_at_startup