import 'package:fl_clash/state.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class AndroidContainer extends StatefulWidget {
  final Widget child;

  const AndroidContainer({
    super.key,
    required this.child,
  });

  @override
  State<AndroidContainer> createState() => _AndroidContainerState();
}

class _AndroidContainerState extends State<AndroidContainer>
    with WidgetsBindingObserver {

  @override
  void initState() {
    super.initState();
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  Future<void> didChangeAppLifecycleState(AppLifecycleState state) async {
    final isPaused = state == AppLifecycleState.paused;
    if (isPaused) {
      await globalState.appController.savePreferences();
    }
  }

  @override
  Widget build(BuildContext context) {
    return widget.child;
  }

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

}
