given this flutter code: import 'package:fluentui/fluentui.dart'; import…
- User
given this flutter code: import 'package:fluent_ui/fluent_ui.dart'; import 'package:window_manager/window_manager.dart'; import 'constants.dart';
void main() async { WidgetsFlutterBinding.ensureInitialized(); await windowManager.ensureInitialized(); windowManager.waitUntilReadyToShow().then((_) async { const size = Size(900, 700); await windowManager.setTitle(Constants.myTitle); await windowManager.setTitleBarStyle(TitleBarStyle.normal); await windowManager.setBackgroundColor(Colors.white); await windowManager.setSize(size); await windowManager.setMinimumSize(size); await windowManager.setMaximumSize(size); await windowManager.setResizable(false); await windowManager.setMaximizable(false); await windowManager.center(); await windowManager.show(); await windowManager.focus(); await windowManager.setSkipTaskbar(false); }); runApp(const MyApp()); }
class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application. @override Widget build(BuildContext context) { return FluentApp( debugShowCheckedModeBanner: false, title: Constants.myTitle, theme: FluentThemeData( brightness: Brightness.light, accentColor: Colors.orange), darkTheme: FluentThemeData( brightness: Brightness.dark, accentColor: Colors.orange), home: const MyHomePage(title: Constants.myTitle), ); } }
class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title;
@override State createState() => _MyHomePageState(); }
class _MyHomePageState extends State with WindowListener { final veiwKey = GlobalKey();
@override void initState() { windowManager.addListener(this); super.initState(); }
@override void dispose() { windowManager.removeListener(this); super.dispose(); }
@override Widget build(BuildContext context) { return Text(""); }
@override void onWindowClose() async { bool _isPreventClose = await windowManager.isPreventClose(); if (isPreventClose) { showDialog( context: context, builder: () { return ContentDialog( title: const Text('Confirm close'), content: const Text('Are you sure want to close the app?'), actions: [ FilledButton( child: const Text('Yes'), onPressed: () { Navigator.pop(context); windowManager.destroy(); }, ), FilledButton( child: const Text('No'), onPressed: () { Navigator.pop(context); }, ) ]); }); } } } can you see why the onWindowClose is not producing a dialog
- Assistant
- User
not getting any debug info
- Assistant
- User
for your info this problem is due to the windoManage needing this await windowManager.setPreventClose(true);
- Assistant
- User
using this flutter code @override void onWindowClose() async { print("onWindowClose triggered"); // Debug output bool isPreventClose = await windowManager.isPreventClose(); print("isPreventClose: $isPreventClose");
if (isPreventClose) { showDialog( context: context, builder: (_) { return ContentDialog( title: const Text('Confirm close'), content: const Text('Are you sure you want to close the app?'), actions: [ FilledButton( child: const Text('Yes'), onPressed: () { Navigator.pop(context); windowManager.destroy(); }, ), FilledButton( child: const Text('No'), onPressed: () { Navigator.pop(context); }, ) ]); }); } } } when the Yes button is pressed please amend so that the buttons are idden and are replace with the message "Closing, please wait" - Assistant
- User
- Assistant
- User
there is a small black area on the left botton of the Confirm.. dialogue, probably due to having no buttons
- Assistant