Flutter WidgetsBindingObserver's didChangeAppLifecycleState not being called on Windows Desktop

Viewed 459

The print functions should be called according to the lifecycle transitions, but none of them are being called. To test this, I'm running the app in debug mode and moving it to the background/foreground (i.e. changing to another app and then returning to this app).

What am I doing wrong?

import 'package:flutter/material.dart';

class StopwatchVw extends StatefulWidget {
  const StopwatchVw({Key? key}) : super(key: key);
  @override _StopwatchVwState createState() => _StopwatchVwState();
}

class _StopwatchVwState extends State<StopwatchVw> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance!.addObserver(this);
  }

  @override
  Future<void> didChangeAppLifecycleState(AppLifecycleState state) {
    print('Changed');

    switch (state) {
      case AppLifecycleState.inactive:
        print("Inactive");
        break;
      case AppLifecycleState.paused:
        print("Paused");
        break;
      case AppLifecycleState.resumed:
        print("Resumed");
        break;
      case AppLifecycleState.detached:
        print("Suspending");
        break;
    }
  }

  @override
  void dispose() {
    WidgetsBinding.instance!.removeObserver(this);
    super.dispose();
  }

  @override
    Widget build(BuildContext context) {
      return Scaffold(body: Text('HEY'));
    }

This is my main.dart:

import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:clocker/stopwatch_vw.dart';
import 'package:flutter/material.dart';
import 'package:flutter_acrylic/flutter_acrylic.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Window.initialize();
  await Window.hideWindowControls();

  runApp(const MyApp());

  doWhenWindowReady(() {
    const initialSize = Size(350, 200);
    appWindow
      ..size = initialSize
      ..minSize = initialSize
      ..maxSize = initialSize
      ..alignment = Alignment.bottomRight
      ..show();
  });

  Window.setEffect(
    effect: WindowEffect.acrylic,
    color: const Color.fromARGB(29, 250, 250, 227),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MoveWindow(child: const StopwatchVw())
    );
  }
}
0 Answers
Related