2026-01-26 00:20:52 +09:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
|
|
|
|
|
|
import '../widgets/navigator_widget.dart';
|
|
|
|
|
import 'theme_service.dart';
|
|
|
|
|
|
|
|
|
|
/// Debug service that flip-flops theme and navigator emotion every 2 seconds.
|
|
|
|
|
///
|
|
|
|
|
/// Usage:
|
|
|
|
|
/// ```dart
|
|
|
|
|
/// TestFlipFlopService.instance.start(navigatorKey: _navigatorKey);
|
|
|
|
|
/// // Later:
|
|
|
|
|
/// TestFlipFlopService.instance.stop();
|
|
|
|
|
/// ```
|
|
|
|
|
class TestFlipFlopService {
|
|
|
|
|
TestFlipFlopService._();
|
|
|
|
|
static final instance = TestFlipFlopService._();
|
|
|
|
|
|
|
|
|
|
Timer? _timer;
|
|
|
|
|
bool _running = false;
|
|
|
|
|
|
|
|
|
|
bool get isRunning => _running;
|
|
|
|
|
|
|
|
|
|
/// Start the flip-flop cycle.
|
|
|
|
|
/// Pass the navigator's GlobalKey to trigger emotion changes.
|
|
|
|
|
void start({required GlobalKey<NavigatorWidgetState> navigatorKey}) {
|
|
|
|
|
stop();
|
|
|
|
|
_running = true;
|
|
|
|
|
|
|
|
|
|
_timer = Timer.periodic(const Duration(seconds: 2), (_) {
|
|
|
|
|
// Toggle theme
|
2026-01-26 11:35:17 +09:00
|
|
|
// ThemeService.instance.toggle();
|
2026-01-26 00:20:52 +09:00
|
|
|
|
|
|
|
|
// Surprise the navigator
|
2026-02-04 23:19:24 +09:00
|
|
|
// if (navigatorKey.currentState?.emotion == 'surprise') {
|
|
|
|
|
// navigatorKey.currentState?.reset();
|
|
|
|
|
// } else {
|
|
|
|
|
// navigatorKey.currentState?.setEmotion('surprise');
|
|
|
|
|
// }
|
2026-01-26 00:20:52 +09:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Stop the flip-flop cycle.
|
|
|
|
|
void stop() {
|
|
|
|
|
_timer?.cancel();
|
|
|
|
|
_timer = null;
|
|
|
|
|
_running = false;
|
|
|
|
|
}
|
|
|
|
|
}
|