0

Excuse me, I'm new to Flutter and I'm creating an application that needs to utilize fullscreen mode but also be able to exit it. The only issue with my code is that it forces fullscreen mode at all times, and I would like to give the user the ability to exit fullscreen mode by pressing F11 or ESC. Could you please advise and help?

Runapp

void main() async {
WidgetsFlutterBinding.ensureInitialized();
  await windowManager.ensureInitialized();
  windowManager.waitUntilReadyToShow().then((_) async {
    await windowManager.setFullScreen(true);
    await windowManager.show();
  });
}

2
  • Is this windows or mac? Commented Apr 1, 2024 at 9:35
  • It's a windows app Commented Apr 1, 2024 at 10:04

1 Answer 1

1

Can you try this code? You can change the code as per your need.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await windowManager.ensureInitialized();
  windowManager.waitUntilReadyToShow().then((_) async {
    await windowManager.setFullScreen(true);
    await windowManager.show();
  });
  runApp(const MainApp());
}

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

  @override
  Widget build(BuildContext context) {
    fullScreenToggle() {
      windowManager
          .isFullScreen()
          .then((value) => windowManager.setFullScreen(!value));
    }

    return CallbackShortcuts(
      bindings: <ShortcutActivator, VoidCallback>{
        const SingleActivator(LogicalKeyboardKey.f11): fullScreenToggle,
        const SingleActivator(LogicalKeyboardKey.escape): fullScreenToggle,
      },
      child: const MaterialApp(
        home: Scaffold(
          body: Center(
            child: Text('Hello World!'),
          ),
        ),
      ),
    );
  }
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.