window_close_guard 1.0.0 copy "window_close_guard: ^1.0.0" to clipboard
window_close_guard: ^1.0.0 copied to clipboard

Flutter package for safe window close handling on desktop with confirmation dialog support.

example/example.dart

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'WindowCloseGuard Example',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void didChangeDependencies() {
    super.didChangeDependencies();

    // 1. Full example - custom dialog + cleanup tasks (recommended)
    WindowCloseGuard.initialize(
      context: context,
      onClose: () async {
        // Your cleanup tasks here
      },
      dialogConfig: const CloseDialogConfig(
        title: 'Exit',
        content: 'Are you sure you want to exit?',
      ),
    );

    // 2. Default behavior - shows a generic confirmation dialog
    // WindowCloseGuard.initialize(context: context);

    // 3. Custom dialog only, no cleanup tasks
    // WindowCloseGuard.initialize(
    //   context: context,
    //   dialogConfig: const CloseDialogConfig(
    //     title: 'Exit',
    //     content: 'Are you sure you want to exit?',
    //   ),
    // );

    // 4. Cleanup tasks only, no confirmation dialog
    // WindowCloseGuard.initialize(
    //   context: context,
    //   showDialog: false,
    //   onClose: () async {
    //     // Your cleanup tasks here
    //   },
    // );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('WindowCloseGuard Example'),
      ),
      body: const Center(
        child: Text('Try closing the window!'),
      ),
    );
  }
}
1
likes
160
points
137
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter package for safe window close handling on desktop with confirmation dialog support.

Repository (GitHub)
View/report issues
Contributing

Topics

#window #desktop #close #flutter #lifecycle

Documentation

API reference

License

MIT (license)

Dependencies

flutter, window_manager

More

Packages that depend on window_close_guard