import 'package:design/design.dart';
import 'package:flutter/material.dart';
import 'package:guru_utils/controller/lifecycle_controller.dart';
import 'package:guru_utils/controller/aware/keep_screen_on_aware.dart';

class _KeepScreenOnController extends LifecycleController with KeepScreenOnAware {
  @override
  late final String screenName;

  _KeepScreenOnController({String? screenName}) {
    this.screenName = screenName ?? runtimeType.toString();
  }
}

class KeepScreenOnWidget extends StatelessWidget {
  final Widget? child;
  final _KeepScreenOnController _controller;

  KeepScreenOnWidget({Key? key, String? screenName, this.child})
      : _controller = _KeepScreenOnController(screenName: screenName),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<_KeepScreenOnController>(
        init: _controller,
        builder: (controller) {
          return Listener(
              onPointerUp: (PointerUpEvent event) {
                controller.keep(info: "onPointerUp");
              },
              onPointerCancel: (event) {
                controller.keep(info: "onPointerCancel");
              },
              child: child);
        });
  }
}
